From: Robert Klemme Date: 2007-01-03T02:05:06+09:00 Subject: Re: operator precedence of assignment On 02.01.2007 17:56, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: operator precedence of assignment" > on Tue, 2 Jan 2007 22:26:53 +0900, Daniel DeLorme writes: > | > |How do you think ruby parses this expression? > | a = 1 + b = 2 + c = 4 + d = 8 > | > |Originally I thought that operator precedence would result in > | a = (1 + b) = (2 + c) = (4 + d) = 8 > |and since an assignment requires a variable, that would result in a SyntaxError. > |But instead it seems that everything on the right side of the assignment > |operator is evaluated first: > | a = (1 + (b = (2 + (c = (4 + (d = 8)))))) > | > |That had me really puzzled at first but I guess the behavior makes a certain > |sense, and it's more useful than a syntax error. Ruby's tolerant parser wins again! > > Ah, for your information, that surprised me as well. Perhaps bison > generated parser is smarter and eagerer than I expected. I have no > idea what to do. I think Daniel did not want you to do anything - in fact he seems rather positively amazed. :-) (The only thing that comes to mind is thank him for the praise. :-)) Kind regards robert