------art_58696_13725971.1169925981534
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 1/27/07, Thomas Hafner <thomas / hafner.nl.eu.org> wrote:
>
> "robin" <robin.houston / gmail.com> wrote/schrieb <
> 1169920481.252703.112350 / a75g2000cwd.googlegroups.com>:
>
> >   2.times{|n| i,j  ,i; puts "ii}, jj.inspect}"}
> >
> > Can you explain why j is nil rather than 0, the second time round?
>
> I'll try. Everytime the block is executed, new variables n, i and j
> are created, because they don't already exist outside the block. If
> you want i to be shared, it should already exist before, e.g.:
>
>   i  il
>   2.times{|n| i,j  ,i; puts "ii}, jj.inspect}"}


maybe OP thought that
i,j  ,i
is semantically equivalent to
ijbut it is not :(, which is good :)
the assignments are performed in parallel, and i is still nil when assigned
to j.
But this is very useful thus one can e.g. swap
the value of two variables as follows

a,b  ,a

HTH
Robert

> Regards
>   Thomas
>
>


-- 
"The best way to predict the future is to invent it."
- Alan Kay

------art_58696_13725971.1169925981534--