lua-users home
lua-l archive

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

Mike Pall wrote:
>   local shl = infix(function(a, b) return a*(2^b) end)
>   print(5 -shl- 4)
>   --> 80
> Cute, huh? Advantage: no changes to the Lua core needed.
> Drawback: one table allocation per operation.

Very nice syntax. Coupled with a simple token filter that's a very clean
way to add any operator. Managing precedence may be a bit tricky though.