Ross Bamford
4/25/2006 10:22:00 AM
On Tue, 25 Apr 2006 11:03:04 +0100, Minkoo Seo <minkoo.seo@gmail.com>
wrote:
> Then, I guess parenthesis is needed only if an expression or a
> funcation call with arguments is used as an argument to the other
> function like:
>
> Array.new 3, 1 (Okay. Two arguments for Array.new)
> p Array.new 3, 1 (Warning.)
>
> 1.+2 (Okay. One argument for 1.+)
> p 1.+2 (Warning.)
>
> The warning is raised because "p foo a, b" can be either "p(foo(a,b))"
> or "p(foo(a), b)." However I also have a counterexample to my theory:
>
> 1+2 (Okay, and it is an obvious method call "1.+(2)")
> p 1+2 (1+2 is passed as an argument to p, but I got no warning. Why?)
> p 1.+2 (Warning. This make sense.)
>
> Any comments?
>
I think p 1+2 doesn't produce a warning because these expressions are
treated specially by the parser, so the implied knowledge of the .+ .- etc
methods means there's no ambigutity at parse time. It's effectively always
parsed as:
p 1.+(2)
--
Ross Bamford - rosco@roscopeco.remove.co.uk