b = i if i = a doesn't work?

T

Trans

Recently I was suprised by the behavior of "start = lambda { start }".
Now that I understand that, I am suprised that

a = 1
b = i if (i = a)

doesn't work.

T.
 
D

Devin Mullins

Trans said:
Recently I was suprised by the behavior of "start = lambda { start }".
Undecorated symbols aren't interpreted until they're executed. Ruby
doesn't even know if the 'start' symbol inside the { ... } is a method
or a local variable until it gets there. That's how I got away with a
lot of my poetry stuff (and how other's've done the same). So "start =
lambda { ADOSdsgfsdgsjT___SDdddd_____222__S224444449
soduihgsoihosidho5s2405987soos23h }" works just as well. (Hadn't
followed the previous thread; you might've already figured this out.)
Now that I understand that, I am suprised that

a = 1
b = i if (i = a)

doesn't work.
Yeah, that's just weirdness. Possibly because Matz feels local
side-effects should move from left to right? In any case, you can do
a = 1
if (i = a) then b = i end
instead.

Devin
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: b = i if i = a doesn't work?"

|>Recently I was suprised by the behavior of "start = lambda { start }".
|
|Undecorated symbols aren't interpreted until they're executed.

"executed" is not a precise word. Local variables are not recognized
until their first assignments are seen in the program. In the
original case,

b = i if i = a

the first assignment "i = a" comes after the reference to the variable "i".

matz.
 
M

Mark Hubbart

Recently I was suprised by the behavior of "start =3D lambda { start }".
Now that I understand that, I am suprised that
=20
a =3D 1
b =3D i if (i =3D a)
=20
doesn't work.

There was a thread on this a while back; apparently it is difficult to
implement this under the current parser:
http://rubyurl.com/k0u [1]

In the course sof the discussion, a patch was offered; but its creator
(the venerable Nobu) labeled it as a dirty hack.

cheers,
Mark

[1] http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/4c3ba45=
c808fbc46/229fdffcbc165af8?tvc=3D1&q=3Donly+if+object+exists#229fdffcbc165a=
f8
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,517
Latest member
TashaLzw39

Latest Threads

Top