[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02714] Re: Append alias for Array.append?

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-05-10 17:31:27 UTC
List: ruby-talk #2714
>As a conclusion, since I was pretty impressed by [ruby-talk:02679], I

I'm not writing this as a opposite argument. In a same spirit, this is a
conclusion from my side.

>think I'm not going to introduce append method.  It may make
>ex-Pythoneers easy, but may confuse ex-Lisper.

Actually I wasn't thinking so much particular languages when I proposed
append.  I was thinking about readibility. Using push in Perl for few years
I'm feeling totally home using it. I just think that aliases *are* good
thing to have around and writing 'hash.has_key? foo' sometimes instead of
'hash.include? foo' makes your code easier to read and maintain. Following
same logic array.append is a really logical continuation.

So to be complete (to certain level) I'd like to propose:

x = [1,2,3]
y = 4
z = [5,6]

a = x
a.push(y)   #=>[1,2,3,4]
a.push(y,z) #=>[1,2,3,4,[5,6],4]

a.pop()     #=>[1,2,3,4,[5,6]]
a.pop(y)    #=>[1]                    (1)

append  should be alias to push
xxx     should be alias to pop

prepend should be alias to unshift
yyy     should be alias to shift


Note for (1)
it would be nice to write 

  b[2,3] = a.pop(3)

instead of

  2.down_to(0){ |i| b[2+i] = a.pop() }

or

  b[2,3] = a[-3,3]
  a[-3,3] = []

or something similar. This might or might not be in line with the push and
the rest depending on a viewpoint.

>It may make ex-Pythoneers easy, but may confuse ex-Lisper.
>  (append '(a b c) 'd)
>  (append '(a b c) '(d e f))

What this does by the way?

	- Aleksi

In This Thread

Prev Next