lua-users home
lua-l archive

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




On 7/20/2016 12:51 PM, Philipp Janda wrote:
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

Of course, my memory is murky, the actual notation used was \name in place of name(a,b). There were other interesting notations in the language, including data sources and sinks, and a novel parser that handled ambiguity by simply retaining all possible parses at once and hoping that the actual meaning would settle out eventually. It was also possible (and encouraged) to modify the syntax of the language itself on the fly...

Now I'm wondering how crazy would it be to build an ICL implementation on top of Lua. Hmm. Like I really need another side project...

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

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

Nifty indeed. And not really any crazier than other tricks we use like implementing try/catch with functions. It does have the same quirks with precedence of course without a whole lot of extra cleverness.

--
Ross Berteig                               Ross@CheshireEng.com
Cheshire Engineering Corp.           http://www.CheshireEng.com/
+1 626 303 1602