lua-users home
lua-l archive

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


Thanks for coming back to the original topic of the thread. I must say, MoonScript has a very nice syntax in general. It has the expressivity of Python but seems able to keep the underlying simplicity and versatility of Lua. 


On Sat, Apr 13, 2013 at 5:03 AM, steve donovan <steve.j.donovan@gmail.com> wrote:
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 Lua.org, PUC-Rio
Lua Macro 2.3.0 Copyright (C) 2007-2011 Steve Donovan
> f = \x(x+1)
> = f(2)
3

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
3

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

steve d.


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