|
Chaining functions to each other can be done already, by returning a function that then again gets called, until the end says () or similar.
I've used this somewhere, guess it was a 'switch' implementation. But you're right, the "function()" token itself makes it a bit uneasy on the eyes.
Here's two lines from luaSub's (one of those dreaded 'macro' packages :) tests/test-do.lua:
<< f do print "not" end function() print "quite" end do print "yet!" end-- f ( function() print "not" end ) ( function() print "quite" end ) ( function() print "yet!" end )
<<First line is the modified syntax and the latter is what is fed to Lua core.
'f' is defined as: function f(x) x() endThis needs two changes in the Lua parser: allowing 'do' as 'function ()' and allowing function blocks as paranthesis-less args, just like func"" and func{} already are.
-asko Mark Hamburg kirjoitti 11.1.2008 kello 23:35: ...
Another example, this time sparked by reading Rob Pike's structural regularexpressions paper, what if one could write something like: local filter = TextFilters.Filter match "(.+/n)+" -- split into multi-line chunks if_find "%%A.*Bimmler" -- check for author match ".+/n" -- split into lines if_find "%%T" -- find title lines print_text() -- print the current line endEach of the operations would work by adding an element to the filter chain.Running the filter would then process the chain.I'm sure that the various macro systems floating around could support this, but they aren't going to be easy to construct. Ruby manages to make these sort of constructs easy without needing to resort to macros. Let's explorewhy... ...