lua-users home
lua-l archive

Re: Macros and expressivity

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


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() end
This 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 regular
expressions 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
 end
Each 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 explore
why...
...

AltStyle によって変換されたページ (->オリジナル) /