lua-users home
lua-l archive

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

Norman Ramsey <> writes:

>  > steve donovan <> writes:
>  > 
>  > > PS the more I play with things like |x| x*(x-1), I wish that this
>  > > syntax was supported in vanilla Lua. A very convenient bit of
>  > > syntactical sugar if you are fond of the functional style.
>  > 
>  > function(x) return x*(x-1) end
>  > 
>  > is terse enough not to pine for shortcuts looking like line noise.
> No it's not.  I've written too much "\x -> x * (x-1)" to be satisfied
> with standard Lua syntax.  This syntax, from Haskell, looks
> like line noise only if you've never seen lambda calculus.

And other line noise looks like line noise only if you've never seen C.
Or BNF.  Or Python.  Or Perl.  Or awk.  Or ada.  Or APL.  Or Scheme.

> Look at the information design: in the standard Lua example you give,
> there are 30 characters of which 8 are unique to this particular
> function, and the rest are syntactic noise.  The Haskell version is 15
> characters with 10 unique ones, or if you compress to "\x -> x*(x-1)"
> (apples to apples), 13 characters of which 8 are unique to the
> function.  The information density for the Haskell syntax is much
> higher.

Information density is not a Lua design goal.  Use APL if you are
concerned about that.

> Lua's standard syntax militates against anonymous functions,

No, it doesn't.  It is one of the most concise _procedural_ languages in
existence for creating and accessing anonymous functions.

> and it often drives what would be one-line functions onto a second
> line.

Write APL.

> For example this simple example does not fit in 80 columns:
>   local sizes = return s:gsub('%A', ''):lower() end, names)
> but
>   local sizes =\s -> s:gsub('%A', ''):lower(), names)
> fits easily and is (in my opinion) easier to read.

For somebody not knowing the construct?  Hardly.

> I recognize that Lua is not an expression-oriented language and that a
> special syntax for functions does not meet Lua's goal of being easily
> accessible to Pascal programmers.  But it frustrates me that Lua is a
> functional language with full lexical closures and yet the syntactic
> overhead for anonymous functions is a heavy burden.

Lua is a _procedural_ language.  Which is why functions have a _return_
statement, all control structures _don't_ return values, and values are
_assigned_ to variables rather than bound.

> (I'm also frustrated that the library support for functional
> programming is is a function I had to define myself.)

So you are frustrated that Lua is not Haskell or Scheme.  Other people
are frustrated because it is not C++ or Ada.

I would be frustrated when Lua were not Lua.

David Kastrup