lua-users home
lua-l archive

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


On Sunday 10 August 2008, Veli-Pekka Tätilä wrote:
> Again, Lua does not have all that syntactic sugar to make this very useful.
> I don't think it should, either.

IMO, that's the whole point.  a big design choice in both Perl and Python 
(don't know about Ruby) is making common idioms very easy to type and read. 
the cost is not only lots of syntactic sugar; in some cases it downright deep 
magic embedded in the language's core.

> http://vtatila.kapsi.fi/luatut.html
>
> PS: in a way the anonymous function syntax of Lua is extremely logical.
> Like a function without the name, with the parameter list, return statement
> and all.

one pet peeve of mine is how so many developers approach learning new 
languages: trying to understand the new language in terms of the old one, and 
when they found something that's "better" in the old, they try 
to "compensate" by writing huge libraries to make up for "missing" features.

usually, after some real world practise with the new language, one finds out 
that maybe those features weren't missing; but a totally different point of 
view makes the difference irrelevant, and sometimes even 'liberating'.

that said, it's always instructive to compare different ways to solve common 
problems, and the more languages one knows, the easiest it is to learn more 
and more.  in my own case, i tried several times to learn Lisp and/or Scheme, 
but i never really grok them (even if my first C program was a (very limited) 
Lisp interpreter); but after learning Lua, i could understand a lot more of 
Scheme, up to the point of writing a few real world programs.

personally, i think Perl and Python are too magic-heavy to be ideal reference 
points.  specifically about anonymous functions, Lua's approach is close to 
Scheme; given that named functions are a special case, just a very thin 
syntax sugar over anonymous ones.

and, about your complain: what i've found is that anonymous functions are very 
neat as function parameters, even when you can't reasonably fit them in 
one-liners. certainly in "map (function(e) return e end, list)" the 'return' 
and 'end' feel too big for the line, but written like this:

map (function (e)
	return e
end, list)

makes the verbosity more palatable, and for longer functions the overhead 
becomes unimportant.  in fact, since i learnt Python after Lua, i found the 
lambda() syntax too limiting, and i'd really like if i could write anonymous 
multi-line functions as parameters.  of course, with the 
white-space-sensitive syntax of Python, the formatting issues get in the way, 
and it's finally better to just give those functions a name. (or, write some 
foundation functions, that allow you to expres what you need with shorter 
expressions, making lambda()'s and generators not only possible, but really 
readable)

-- 
Javier

Attachment: signature.asc
Description: This is a digitally signed message part.