[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:02198] Re: parse bug in 1.5

From: Mirko Nasato <mirko.nasato@...>
Date: 2000-03-27 23:01:28 UTC
List: ruby-talk #2198
On 26 Mar 2000, Yukihiro Matsumoto wrote:
> 
> |Ruby 1.5 seems to have a problem when parsing methods called
> |with a {...} block if there is space before the opening paren.
> 
> It's not a bug.  It is a bad feature which I'm thinking about
> improvement, and not yet come to conclusion. ;-)
> 
Most languages allow for space between the function identifier and
the opening parenthesis, so i thought it was possible in Ruby, too.

> In 1.4.x, identifiers followed by parenthesises is considered as
> method invocation.  In 1.5.x, if whitespaces comes between identifiers
> and parenthesises, parenthesises are considered as expression
> grouping, to enable:
> 
>   point.move (1+3)*2, 5
> 
That's an interesting feature, indeed.

  ruby1.4 -e 'print (1+3)*2, "\n"'  => parse error
  ruby1.5 -e 'print (1+3)*2, "\n"'  => 8
  perl -w -e 'print (1+3)*2, "\n"'  => 4 (+ amusing warnings)

> They are parsed like this (parenthesises added):
> 
> |  greet ("Matz") { "Ciao" }
> |
> |    => Ciao Matz!   # ruby 1.4.3 (1999-12-08)
> 
>   greet("Matz"){ "Ciao" }	#=> OK
> 
> |    => parse error  # ruby 1.5.3 (2000-03-23)
> 
>   greet(("Matz"){ "Ciao" })	#=> error
> 
If i did understand, there are two problems here.

The first is that a {...} block is always included in the (...)
arg list.  (But "func {...}" == "func {block}", not "func({hash})".)

Maybe it could be included only when it follows a "," ?

  func arg, {...}  ==  func(arg,{hash})
  func arg {...}   ==  func(arg){block}  # currently unsupported

The second is that a space after the method identifier seems to be 
always interpreted as an implicit "(", leading to this inconsistency

  print ("Ciao\n")     ==  print(("Ciao\n"))     # OK
  print ("Ciao","\n")  ==  print(("Ciao","\n"))  # error

I guess LISP syntax is simpler to parse. ;-)

Regards,

-- Mirko Nasato

In This Thread

Prev Next