lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Thanks - I clearly should look into this stuff, it looks really powerful.

However at a formal (rather than implementation) level would using an unadorned token really cause ambiguities? It would be neater without a special syntax and it should surely be possible to disambiguate this given that the compiler knows that the token refers to a function (or not). I'd kind of like to add "mathematical" convention multiplication too i.e. a b is interpreted as a * b.

On 11/29/06, *Fabien* < <>> wrote:

   On 11/29/06, *John Hind* <
   <>> wrote:

       I'd like to be able to offer extensible infix operators so
       you'd be able to write something like:

       c = a func b
       This would be evaluated as:
       c = func(a, b)

   I really like Haskell's solution, which allows to put arbitrary
   functions in infix position, if you put it between backquotes, as
   in: "a `func` b". Unfortunately, it clashes with my syntax for
   algebraic datatypes

On second though, it doesn't clash. It's actually a straightforward extension to implement:

-{ mlp.expr.add_postfix_sequence{ "`", <>, "`", mlp.expr,
    prec = 30, assoc = "left", builder = |x| `Call{ x[2], x[1], x[3] } } }

But there's still an issue, it relies on a partially unimplemented feature of the grammar generator: precedence and associativity hints aren't handled properly by postfix sequences, so the extension above will behave as if it had infinite precedence and were right associative. But that will be fixed eventually, so this infix call extension will work.