From: grady@... (Steven Grady) Date: 2000-12-02T08:40:06+09:00 Subject: [ruby-talk:6726] Re: behavior of Proc#arity? Matju responds: >this was part of a thread on the same topic as this one. (Thanks for the pointer to the previous thread -- unfortunately, I have only been playing with Ruby for a few days, so I missed that discussion. Next time, I'll check the mail archive!) >> of parallel assignment". But there is no such thing as "parallel >> assignment" for a single variable, so I think that passage does >> not explain things. > >In message 6339, I gave an example of parallel assignment for 1 var: > >a = [1] #=> [1] >a #=> [1] >a,= [1] #=> [1] >a #=> 1 Hm. I agree that that's parallel assignment for 1 var, but it is doesn't clarify the case Matz brought up. From the book (p. 222): If the assignment contains multiple lvalues and one rvalue, ... [Note that this does _not_ refer to multiple rvalues and one lvalue] If there are more rvalues than lvalues, the excess will be ignored. [This explains your behavior above, but note that it requires the extra "," after the a. The point of my question was that the magic behavior of |a| happened when there is _not_ a ",".] In particular, I see nothing that explains: p1 = proc {|a| a} p1.call(1) #=> 1 p1.call(1, 2) #=> [1, 2] If we compare this to parallel assignment, we would have to say that a is the lvalue, and the arguments to p1.call() are the rvalues. Hence: a = 1 #=> 1 a = 1, 2 #=> Syntax Error Alternatively: p2 = proc {|a,| a} p2.call(1) #=> 1 p2.call(1, 2) #=> Argument Error p2.call([1]) #=> [1] Yield functions the same way as Proc#call, BTW: def x(*a) yield *a end x(1) {|a| a} #=> 1 x(1, 2) {|a| a} #=> [1, 2] "*args" functions differently: def y(*a) a end y(1) #=> [1] So, I have to ask again: Is the magic behavior of |a| documented anywhere? -- Steven "So whaddya want? Wicker?!?"