From: Niklas Frykholm Date: 2001-08-08T16:15:20+09:00 Subject: [ruby-talk:19356] Re: Help with ternary operator syntax and grammar > 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? There is a third example to consider 1: print cond == 1 ? ", " : "\n" 2: print (cond == 1) ? ", " : "\n" 3: print(cond==1) ? ", " : "\n" In 1 and 3 the semantic is obvious -- if you want to follow standard conventions. In 2 it is less obvious. You have to pick one meaning 1 or 3 or generate a syntax error and whatever you do you will probably annoy or confuse some people. (Personally, I tend to go with 1 even though it makes the parsing whitespace-dependant.) For clarity, it is probably best to always use parenthesis in the method call when you have complex arguments: print( (cond==1) ? ", " : "\n" ) // Niklas