[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

odd error

Roger Pack

11/9/2007 11:13:00 PM

irb(main):006:0> {}.merge {:a => 3}
SyntaxError: compile error
(irb):6: syntax error, unexpected tASSOC, expecting '}'
{}.merge {:a => 3}

???
{}.merge({:a => 3}) works, though. Is this a grammar problem?
--
Posted via http://www.ruby-....

2 Answers

Bob Hutchison

11/9/2007 11:20:00 PM

0


On 9-Nov-07, at 6:13 PM, Roger Pack wrote:

> irb(main):006:0> {}.merge {:a => 3}
> SyntaxError: compile error
> (irb):6: syntax error, unexpected tASSOC, expecting '}'
> {}.merge {:a => 3}
>
> ???
> {}.merge({:a => 3}) works, though. Is this a grammar problem?


Ambiguity I guess.

It is taking the {:a => 3} as a block rather than as a hash argument
(merge is defined to allow that). The parenthesis resolves the
ambiguity.

Cheers,
Bob

----
Bob Hutchison -- tumblelog at http://www.recurs...
Recursive Design Inc. -- weblog at http://www.recursiv...
http://www.rec... -- works on http://www.raconteur.info/cms-for-static-con...



Arlen Cuss

11/10/2007 12:40:00 AM

0

Hi,

On Sat, 2007-11-10 at 08:19 +0900, Bob Hutchison wrote:
> On 9-Nov-07, at 6:13 PM, Roger Pack wrote:
>
> > irb(main):006:0> {}.merge {:a => 3}
> > SyntaxError: compile error
> > (irb):6: syntax error, unexpected tASSOC, expecting '}'
> > {}.merge {:a => 3}
> >
> > ???
> > {}.merge({:a => 3}) works, though. Is this a grammar problem?
>
>
> Ambiguity I guess.
>
> It is taking the {:a => 3} as a block rather than as a hash argument
> (merge is defined to allow that). The parenthesis resolves the
> ambiguity.

Right. "=>" is the tASSOC that ruby's talking about. Since it thought
you were having a block there, the only valid thing you could have
after :a would be an end of block (i.e. :a is your return value).

> Cheers,
> Bob


Arlen