summaryrefslogtreecommitdiff
path: root/Tools/LuaMacro/macro/lambda.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/LuaMacro/macro/lambda.lua')
-rw-r--r--Tools/LuaMacro/macro/lambda.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/Tools/LuaMacro/macro/lambda.lua b/Tools/LuaMacro/macro/lambda.lua
new file mode 100644
index 0000000..677f997
--- /dev/null
+++ b/Tools/LuaMacro/macro/lambda.lua
@@ -0,0 +1,22 @@
+--- Short anonymous functions (lambdas).
+-- This syntax is suited
+-- to any naive token-processor because the payload is always inside parens.
+-- It is an example of a macro associated with a 'operator' character.
+--
+-- Syntax is `\<args>(<expr>)`
+--
+-- `\x(x+10)` is short for
+-- `function(x) return x+10 end`. There may be a number of formal argumets,
+-- e.g. `\x,y(x+y)` or there may be none, e.g. `\(somefun())`. Such functions
+-- may return multiple values, e.g `\x(x+1,x-1)`.
+--
+-- @module macro.lambda
+
+local M = require 'macro'
+
+M.define ('\\',function(get,put)
+ local args, body = get:idens('('), get:list()
+ return put:keyword 'function' '(' : idens(args) ')' :
+ keyword 'return' : list(body) : space() : keyword 'end'
+end)
+