lua-users home
lua-l archive

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


At 08:48 AM 6/29/2011, Lorenzo Donati wrote:
....
Arbitrary custom operators.
....
For example, consider math vectors:

W = V1 :x: V2 + V3
W = V1:cross_product(V2) + V3   -- less readable


a = (V1 [.] V2) / |V1 [.] V2|
a = V1:dot_product(V2) / V1:dot_product(V2):abs()  -- less readable

Back in the dark ages (ca. 1986 or so) I used a novel little language called ICL that had been design at least partly to enable research into silicon compilation. (This was before VHDL took over the niche.)

One of its interesting features was the ability to write new infix operators by way of a bit of syntax sugar that converted a generic infix operator into a call of a function with two parameters. Specifically, a notation like

    a //FOO\\ b

was treated converted to a conventional call like FOO(a,b). I don't recall how this interacted with precedence rules, or if it was possible to specify the relative precedence of such function calls. It did go a long way towards cleaning up situations like the example above...

Ross Berteig                               Ross@CheshireEng.com
Cheshire Engineering Corp.           http://www.CheshireEng.com/