lua-users home
lua-l archive

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


Am 20.07.2016 um 21:06 schröbte Ross Berteig:

I once encountered a language[1] which had syntax for infix notation
function calls, allowing new binary operators to be introduced as simple
functions of two arguments. So:

local M=17 -- upvalue for modulus
local function addm(a,b) return (a+b)%M end -- modular addition
local n = 16
print( n /addm\ 1 )         -- 0

Not sure the specific notation of /name\ feels like it fits the tone of
Lua code, but it was a convenient way to make arbitrary data types with
an expressive grammar. I don't recall if there was a way to declare
precedence, or if it was left to right.

Haskell can do that as well[2] using backticks. But those were not included in the 100+ operators I mentioned ...

Also, I think someone posted a nifty syntax trick for infix functions in Lua:

    infix( 12 ,add, 13 ,mul, 8 )

I believe the OP was this[3] here.


Philipp

  [2]: https://wiki.haskell.org/Infix_operator
  [3]: http://lua-users.org/lists/lua-l/2011-12/msg00533.html