lua-users home
lua-l archive

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


On Fri, 26 Nov 2010 21:10:10 +0200, Mark Hamburg <mark@grubmah.com> wrote:

At the risk of having accusations of Perlishness flung around, there's also the option of just optimizing the single-parameter, single-expression case and introducing a token like $ which essentially turns anything it touches into a function with spreading "contamination":

	$ --> function( x ) return x end
	$ + 1 --> function( x ) return x + 1 end
	( $ + 1 ) * $ --> function( x ) return ( x + 1 ) * x end
	$ - x --> function( y ) return y - x end


Too tricky. One must arbitrarily chose where to stop contamination in the
grammar. Consider:

 ? --> return some_proxy_obj[function( x ) return x end]
 ? --> return function( x ) return some_proxy_obj[x] end

? --> return function( x ) return math.sin(x) end, function return math.cos(x) end
 ? --> return function( x ) return math.sin(x), math.cos(x) end

Note that ... token already stands for "arguments".
So if 'return' in expression context would define anonymous vararg function,
greedily matching comma separated list of expressions
(this is the second time I try to push this idea, because it looks
very cute), then your examples could look like:

$ --> return (...)
$ + 1 --> return ... + 1
( $ + 1 ) * $ --> (return ( ... + 1 ) * ...)
$ - x --> return ... - x