On Fri, Feb 19, 2010 at 5:02 PM, Raul Jara <raul.c.jara / gmail.com> wrote:

> But the parser knows what's a method and what's a variable, right? (I'm
> asking.           > variable and what is a method, it can define x y as x(y) when x is a
> method, and x y as x.+(y) when x is a variable.  
No.

First -

In the expression

   x y

It sees x as a method because of the form of the expression. Just as
it does for the expressions

  x(y)

or

self.x y

and if we have:

a = 'x'
b = 'y'

a b

is the same as:

self.a b

not

'x' b

def a(arg)
  "My arg is #{arg}"
end

a = 'string 1'
b = 'string 2'

a b # => "My arg is string 2"

Second, variables in Ruby are untyped references to objects, and not
objects themselves.

So what would the compiler to do with

def two_args(x, y)
   x y
end

two_args('a', 'b')

two_args(1, 2)

Third,

the interpretation of

  'a' 'b'

as 'ab'

Is not really a parser thing, it's a lexical analyser thing.

It's just a rarely used form of string literal which allows for quoted
strings separated by whitespace (or escaped newlines) to be coalesced
before the parser even sees them.

-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale