lua-users home
lua-l archive

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

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.