lua-users home
lua-l archive

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

On Feb 28, 2006, at 12:58 AM, Lisa Parratt wrote:
I'm personally of the opinion that if a piece of syntax appears in Perl, that's an excellent indication it should be avoided like the plague.

That may (or may not) be a reasonably effective general filter, but I think that's a poor hard rule to apply. Gems can be found in the sewagiest places.

Why does everyone always suggest features from that aborted abomination of a language, rather than ones from SPARK, Z, or other languages with a bit of class and back bone?

I this case, the concept of easy-to-type anonymous lambda functions comes from more than just Perl. Lisp and Ruby come to mind. The syntax in Ruby is remarkably similar:

	myHash.each{ |key,value| print( key, value ) }
or (also in Ruby)
	myHash.each do |key,value| print( key, value ) end

In cases where there are no arguments passed to the function, the parameter list can be omitted. Again, in Ruby:

	10.times do
		print( "Hello World" )

In case it's not clear, the above are equivalent to the Lua code:

	table.foreach( myHash, function( key, value ) print( key, value ) end )

and (sort of)

	function times( n, f )
		for i=1,n do
			f( i )
	times( 10, function( )
		print( "Hello World" )
	end )

In my opinion, this is not a case of "I want Lua to be like Perl", but rather "Simple syntax sugar can make the difference between using the power of lambda functions, or deciding that it is too much work to type them. And, hey!, look, Perl has nice syntax for this!"