[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Proposal for a standard way of defining custom operators in Lua
- From: Fabien <fleutot+lua@...>
- Date: Fri, 26 Jul 2013 11:06:59 +0200
By the way, there's a "light and safe" support of infix notations in Haskell, which I like and is supported by metalua: backtick infix functions. "2 `plus` 3" is syntax sugar for "plus(2, 3)".
- backtick operators are always left associative, have all the same precedence (just below arithmetic operators). If it doesn't fit your use case, you need parentheses, both for the parser and for the sanity of anyone reading your code.
- they have actual names, which you can/must choose meaningfully, and which can be pronounced.
- no extensible metatable nonsense, no multiple-dispatch nightmares to resolve operators between heterogeneous operands. It's a plain old function.
- no new tokenization rules, no new keywords.
- still, it's not worth giving up Lua compatibility just for that. If you're using metalua for other reasons, I find them to be a welcome bonus, but that's it.