lua-users home
lua-l archive

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


On Wed, Nov 24, 2010 at 10:44, Dirk Laurie <dpl@sun.ac.za> wrote:
> What puts me off from the current spate of lightweight syntax
> proposals is just the same thing I hate about C and Perl: they
> are cryptic and the saving in keystrokes now is not worth the
> brain pain later.

It's not about keystrokes, but about readability, actually.

The first part of a function literal looks like a function call, and,
for short functions, the `(function( ... ) ... end)` overweights the
content of the function.

In functional or callback heavy code, it really breaks readability.

All the proposed syntaxes depart from the keyword-based syntax, it's
true. It's hard to find a good syntax (one that doesn't generate too
much line noise) for short functions with the current parsing strategy
which isn't going out any time soon.

> The Pascal model has served Lua well so far: keep the language
> itself simple and sweet, and put all the power into libraries.

Adding another syntax for function could be seen as bloat, and
replacing the current syntax for function expressions (not for
statements) would probably result in an outcry on the list.

The Lua authors remain conspicuously silent on the matter. They care a
lot about the look and feel of the language, and the programming
styles that its features enable.

However, they seem to be ambivalent on functions. Their semantics and
implementation is excellent (first class, lexical scope with closure,
tail call elimination) and invite to write functional code, yet the
syntax makes it look like mud.

The aesthetics discussion on the list is a matter of bikeshedding.
I've been trying a slew of different legal syntaxes in order to find
one that doesn't suck too much (legal, unambiguous, distinctive, and
as simple as possible yet as versatile as the long syntax) for the use
cases described above. My favourite one so far is a combination of

    @ [arglist] `(` [explist] `)`
and
    @ [arglist] `[` {statements} => [explist] `]`
or perhaps
    @ [arglist] do {statements} return [explist] end

Other, equivalent or more restrictive ones have been proposed, and as
I said before, its a matter of taste. I don't think we'll get a
consensus on the list on a given syntax.

Kind regards,
-- Pierre-Yves