[Grace-core] another ambiguity in the grammar

Bart Jacobs bart.jacobs at cs.kuleuven.be
Mon Mar 26 03:03:16 PDT 2012


Note that the same problem exists in Ruby.

Ruby seems to resolve this by looking up "a": if it's a method, then 
a[1] applies the method to a list literal; if it's a value, then a[1] 
indexes a. I guess the parser can parse it as a method call; the type 
checker then needs to transform it as appropriate.

Personally, I like this. In particular, this leaves open the possibility 
of using the index notation for concisely calling closures, as in Ruby:

In Ruby (this works today):

foo = proc { | x, y| x + y }
print(foo[1, 2]) # Prints 3

In Grace (today):

def foo = { x, y -> x + y}
print(foo.apply(1, 2)) # Prints 3

Perhaps someday:

def foo = { x, y -> x + y }   # Or: def foo[x, y] { x + y }
print(foo[1, 2]) # Prints 3

Bart

On 25/03/2012 23:07, James Noble wrote:
> The spec currently allows (and minigrace supports)
> the [] operator method to index collections
> and [1,2,3] collection literals
>
> so what's this a[1] indexing a, or calling a passing the literal collection [1]
>
> James
> _______________________________________________
> Grace-core mailing list
> Grace-core at cecs.pdx.edu
> https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm


More information about the Grace-core mailing list