lua-users home
lua-l archive

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

To return to Oliver's question, I think short-function syntax makes particular sense with _interactive_ work. For instance, Francesco Abbate's gsl-shell[1] uses the |x| x+1 short form popularised by metalua to great effect, since one's often creating short functions.

The point is that interactive usage requires finger-friendly syntax that you would not necessarily want in formal code, much as in English contractions like "it's" are not so appropriate in reports.

There are a number of ways to get that informal style. You can use metalua itself interactively.  Or use LuaMacro, which does not care about which Lua version is used:

LuaMacro $ lua52 luam -i
Lua 5.2.2  Copyright (C) 1994-2013, PUC-Rio
Lua Macro 2.3.0 Copyright (C) 2007-2011 Steve Donovan
> f = \x(x+1)
> = f(2)

LM defines a short function form based on a suggestion by lhf (a lexical macro system isn't clever enough to do |x|...)

Or even use a full-blown Lua-based language like MoonScript, which is particularly friendly for interactive work because the call operator has a very low precedence

$ mooni
MoonScript version 0.2.3
Note: use backslash at line end to start a block
> f = (x) -> x+1
> f 2

mooni is an experimental interactive version [2]. Sometimes problems make more sense with a more appropriate notation!

steve d.

[2] 'luarocks --from= install mooni'.  If you don't have Git, then first grab moonscript using regular luarocks server.