From: furufuru@... (Ryo Furue) Date: 2001-08-08T13:35:26+09:00 Subject: [ruby-talk:19341] Re: Help with ternary operator syntax and grammar hipster wrote in message news:... > On Tue, 07 Aug 2001 21:25:06 +0900, Ryo Furue wrote: [...] > > I can't understand what's wrong with this: > > > > cond = true > > print (cond? ", " : "\n") > ^^ > insert a space here. Otherwise Ruby will interpret it as a call to the > function 'cond?'. Question marks are allowed at the end of function > names to indicate predicates. Your other examples were variations on > this theme with differing precedences. Thank you all who responded! Your explanations almost solved the mystery :) But, I think one question remains: cond = true print (cond) ? ", " : "\n" Why does this print "true" on the screen? It seems that the second line is interpreted as (print cond) ? ", " : "\n" But, don't you think this is a weired grammar? In the following, the second line prints ", ", but the third prints "true": cond = 1 print cond == 1 ? ", " : "\n" print (cond == 1) ? ", " : "\n" I think this is very counter-intuitive. What's the rationale for this interpretation? Thank you, Ryo