lua-users home
lua-l archive

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



What would you think of a notation like this?

{
	yyy=	do =something end
	xxx= 	do(a,b) =a+b end
	zzz= 	do(a,b,c) if a then =b else =c end end
}

Will make it a luaSub mod for trial, but thought of asking opinions first.

do ... end	->  	function() ... end
do(...) ... end	->	function(...) ... end

= exp		->	return exp		(within the enclosed block)

Especially the '=' trick is handy, since it makes simple closures readable and does not (is this true?) overlap with existing valid Lua syntax.

-asko


David Manura kirjoitti 7.2.2008 kello 4:30:

Miles Bader writes:
Bret Victor writes:
I thing I like about Lua syntax is that punctuation is kept minimal,
and words are used (in, do, end) when that's how you would read the
code out loud.

I agree, in general -- I don't dislike punctuation heavy languages like C, but Lua has a consistent and attractive style of its own. [Still, in
the middle of an expression, I think a punctuation-oriented lambda
syntax isn't out of place, even in Lua.]

In Lua, we do write "{1,2}" rather than "table 1, 2 end". Given that functions
are fundamental data type, like tables, there is consistency in using
punctuation to denote functions, particularly when used as lambda expressions.

Approaches for syntactically lightweight closures are also discussed in [1].

[1] http://lua-users.org/wiki/ShortAnonymousFunctions