From: David Alan Black Date: 2000-12-04T02:00:56+09:00 Subject: [ruby-talk:6777] Re: behavior of Proc#arity? Hello -- On Mon, 4 Dec 2000, Yukihiro Matsumoto wrote: > |> What do you suppose the value of `a' after `a=1,2'? > |> I think it should be [1,2]. And my copy of miniruby works so now. > | > |Would that imply this: > | > | a,b = 1,2,3 # a==1, b==[2,3] > | > |If so, would the '*' (on the left side, at least) still have > |any separate functionality? > > Well, a = 1,2 is corresponding: > > proc{|a|p a}.call(1,2) > > Thus > > proc{|a|p a}.call(1,2) # a = 1,2; a => [1,2] (new) > proc{|a|p a}.call(1) # a = 1; a => 1 > proc{|*a|p a}.call(1,2) # *a = 1,2; a => [1,2] > proc{|*a|p a}.call(1) # *a = 1; a => [1] > > Now I feel very consistent. Wow -- what's it like? :-) I'm still not clear on the matter of '*' with multiple lvalues. If these two are to be the same: > proc{|a|p a}.call(1,2) # a = 1,2; a => [1,2] (new) > proc{|*a|p a}.call(1,2) # *a = 1,2; a => [1,2] then would these also be the same? proc{|a,b|...}.call(1,2,3) # a,b = 1,2,3; a => 1, b=> [2,3] (new) proc{|a,*b|...}.call(1,2,3) # a,*b = 1,2,3; a => 1, b=> [2,3] Then the '*' would only have any meaning with single arguments, I think, and it would mean "treat the rvalues as an array, even if there's only one of them". Somehow that feels like losing functionality. Then again, right now there are situations in which the trailing comma doesn't matter: a,b = 1,2,3 a,b, = 1,2,3 do the same thing. So maybe there are more syntactical variants than actual different situations.... David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav