lua-users home
lua-l archive

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


   unwind_protect( io.close, f )( function()
       print( f:read( "*a" ) )
   end )

With syntactic sugar for closure arguments, we get:

   unwind_protect( io.close, f ) do
       print( f:read( "*a" ) )
   end

This does not allow arguments, which could be useful for iterated callbacks as in Ruby:
	5.times { |i| ... }
The idea being that it lets the called function "drive" the one passed in.

Assuming the closing parenthesis is the main issue, would it be an idea to look for an alternate notation? Here's a strange one:

	unwind_protect( io.close, f ) # function()
	  print( f:read( "*a" ) )
	end

Taking this further:

	function myif (c,a,b) if c then a() else b() end end

	myif (condition) # function ()
		print "yes"
	end # function ()
		print "no"
	end

Yuck. Just to show what such Smalltalk-like "code bocks" can lead to.

-jcw