lua-users home
lua-l archive

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




On 7/20/2016 7:30 AM, Philipp Janda wrote:
Am 20.07.2016 um 15:20 schröbte Dirk Laurie:
....
Suggestion: make the few special characters we have left
user-configurable. I.e. introduce metamethod names for !x,
x ? y etc even though no native type defines a default meaning
for them.

IMHO, operators only make code easier to read if you have an intuitive
understanding about what the operator is supposed to do and how it
relates to other operators in the same expression (e.g. regarding
precedence). Otherwise it only makes things harder to parse (for
computers and humans alike).

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.

[1]: ICL, an early silicon compiler. It has almost completely vanished from visibility, but Ron's thesis that defined the langauge is available. Worth a read if novel parsing techniques interest you. http://authors.library.caltech.edu/26660/2/postscript.pdf

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