aboutsummaryrefslogtreecommitdiff
path: root/examples/working/macro.ey
diff options
context:
space:
mode:
Diffstat (limited to 'examples/working/macro.ey')
-rw-r--r--examples/working/macro.ey51
1 files changed, 51 insertions, 0 deletions
diff --git a/examples/working/macro.ey b/examples/working/macro.ey
new file mode 100644
index 0000000..fdaf0cf
--- /dev/null
+++ b/examples/working/macro.ey
@@ -0,0 +1,51 @@
+# an alternative to }, moving the top stack element
+# into closure storage and pushing it back before
+# executing the block
+
+{ "}" | *
+ { /f deff /x defv
+ { x f }
+ } quoted { } { * } ? *
+} "}0" defq
+
+5 { { dump }0 } * /dumpfive deff
+5 { dump }0 /dumpfivetwo deff
+
+7 dumpfive -
+7 dumpfivetwo -
+
+
+# import members of other objects into local scope
+
+{
+ "_" | "-021" | ".|" | "-01" | |deff
+} /usef defq
+
+
+# codewalker
+
+{ "lol" dump } /lol deff
+
+{
+ 1 /cont defv
+
+ { cont } { 0 {
+ exe /walkelem deff
+ { sys .out .writestr } /out deff
+
+ _ { { " " out } rep }0 /indent deff
+ { 2 add walkelem }0 /walk deff
+
+ _ code [ {
+ indent [ "\"" -102 "\"\n" ] |out each
+ } {
+ indent _ sym _ out
+ "{" streq { 0 =cont |lol } { - } ? *
+ "\n" out
+ } {
+ blk |walk each
+ } ] * *
+ } * } loop
+} /codewalk defq
+
+{ f "t" g h { a b { c d } e } codewalk } *