[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[BUG] Unexpected syntax error

Daniel Harple

2/20/2006 12:11:00 AM

$ ruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]

# Example to illustrate the problem
def foo1
p (1..10).method(:each)
end

def foo2()
p((1..10).method(:each))
end

def foo3()
p (1..10).method(:each)
end

foo1 # -> No error
foo2 # -> No error
foo3 # -> Error

__END__

-- Daniel


3 Answers

Park Heesob

2/20/2006 1:08:00 AM

0

Hi,


>From: Daniel Harple <dharple@generalconsumption.org>
>Reply-To: ruby-talk@ruby-lang.org
>To: ruby-talk@ruby-lang.org (ruby-talk ML)
>Subject: [BUG] Unexpected syntax error
>Date: Mon, 20 Feb 2006 09:10:54 +0900
>
>$ ruby -v
>ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]
>
># Example to illustrate the problem
>def foo1
> p (1..10).method(:each)
>end
>
>def foo2()
> p((1..10).method(:each))
>end
>
>def foo3()
> p (1..10).method(:each)
>end
>
>foo1 # -> No error
>foo2 # -> No error
>foo3 # -> Error
>
>__END__
>
>-- Daniel
>
It reminds me an old thread
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...


def foo1
p (2.4/0.2).to_i
end
def foo2()
p ((2.4/0.2).to_i)
end
def foo3()
p (2.4/0.2).to_i
end

foo1 # -> 11
foo2 # -> 11
foo3 # -> 12.0

__END__

Regards,

Park Heesob




Eric Hodel

2/20/2006 7:08:00 PM

0

On Feb 19, 2006, at 4:10 PM, Daniel Harple wrote:

> $ ruby -v
> ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]
>
> # Example to illustrate the problem
> def foo1
> p (1..10).method(:each)
> end
>
> def foo2()
> p((1..10).method(:each))
> end
>
> def foo3()
> p (1..10).method(:each)
> end
>
> foo1 # -> No error
> foo2 # -> No error
> foo3 # -> Error

Ruby thinks those are argument parentheses. This may not be a bug.

-:11: warning: don't put space before argument parentheses
#<Method: Range#each>
#<Method: Range#each>
1..10
-:11:in `method': undefined method `each' for class
`NilClass' (NameError)
from -:11:in `foo3'
from -:16
$ parse_tree_show -f
p (1..10).method(:each)
(eval):1: warning: (...) interpreted as grouped expression
[[:class,
:Example,
:Object,
[:defn,
:example,
[:scope,
[:block,
[:args],
[:fcall,
:p,
[:array, [:call, [:lit, 1..10], :method, [:array,
[:lit, :each]]]]]]]]]]

--
Eric Hodel - drbrain@segment7.net - http://se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...




Yukihiro Matsumoto

2/20/2006 11:58:00 PM

0

Hi,

In message "Re: Unexpected syntax error"
on Tue, 21 Feb 2006 04:07:51 +0900, Eric Hodel <drbrain@segment7.net> writes:

|Ruby thinks those are argument parentheses. This may not be a bug.

This is a bug, and I fixed it last night(JST).

matz.