[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: ideas for lambda syntax
- From: steve donovan <steve.j.donovan@...>
- Date: Sat, 13 Apr 2013 11:03:25 +0200
To return to Oliver's question, I think short-function syntax makes particular sense with _interactive_ work. For instance, Francesco Abbate's gsl-shell 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 Lua.org, 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
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 . Sometimes problems make more sense with a more appropriate notation!
 'luarocks --from=http://rocks.moonscript.org
install mooni'. If you don't have Git, then first grab moonscript using regular luarocks server.