From: Gregory Brown Date: 2008-08-02T05:40:30+09:00 Subject: Re: Help finding this syntax error On Fri, Aug 1, 2008 at 4:33 PM, Adam Shelly wrote: > On 8/1/08, Patrick Li wrote: >> Nope. that's not quite it. i'm really quite stumped. >> >> syntax error, unexpected tSYMBEG, expecting ')' (SyntaxError) >> if(FieldTypes.key? field && FieldTypes[field].respond_to? :select) >> ^ from >> -e:1 > > Apparently the parser just can't recognize function calls inside > conditions unless they have the parens: > > irb(main):013:0> if (true && p 1) > irb(main):014:1> p :hi; end > SyntaxError: compile error > (irb):13: syntax error, unexpected tINTEGER, expecting kDO or '{' or '(' > if (true && p 1) This isn't actually the case, it has to do with the fact that && binds tightly. 'and' and 'or' have less tight binding and work as you'd expect. >> if true and p 1 >> p :hi >> end 1 :hi So... if Ruby sees if (true && p 1), it parses it as: if ((true && p) 1) but using if (true and p 1), Ruby sees: if (true and p(1)) HTH, -greg --- Killer Ruby PDF Generation named after a magnificent sea creature: http://github.com/sandal/prawn | Non-tech stuff at: http://metametta.blogspot.com