about summary refs log tree commit diff stats
path: root/generic.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-27 05:18:40 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-27 05:23:22 -0800
commit6952b8f0693920b7ad27793a75defaca5ef31a9d (patch)
tree53b41bab071a46adaab05d507fb9329d09a7f2de /generic.mu
parenta069fd623df37f29cc97cca74b1fe74abfc658de (diff)
downloadmu-6952b8f0693920b7ad27793a75defaca5ef31a9d.tar.gz
344 - about to give up on rewrite rules
I wanted to come up with some way to rewrite 'def-clause foo' to 'after
foo/more-clauses', something like:

  rewrite def-clause [
    (fn-name string-address) <- arg
    (label-name string-address) <- strcat (fn-name string-address deref) ("/more-clauses" literal)
    (body expr) <- arg
    reply `(after ,label-name ,body)
  ]

But the quasiquote is still a nested expression that doesn't fit our
model well.

Still an open question how to do template interpolation in mu.
Diffstat (limited to 'generic.mu')
-rw-r--r--generic.mu5
1 files changed, 2 insertions, 3 deletions
diff --git a/generic.mu b/generic.mu
index b37b5208..e73612c5 100644
--- a/generic.mu
+++ b/generic.mu
@@ -5,6 +5,7 @@
 (def factorial [
   ((default-scope scope-address) <- new (scope literal) (30 literal))
   ((n integer) <- arg (0 literal))
+  more-clauses
   ((x integer) <- sub (n integer) (1 literal))
   ((subresult integer) <- factorial (x integer))
   ((result integer) <- mul (subresult integer) (n integer))
@@ -12,9 +13,7 @@
 ])
 
 ; def factorial 0 = 1
-(def factorial [
-  ((default-scope scope-address) <- new (scope literal) (30 literal))
-  ((n integer) <- arg (0 literal))
+(after factorial/more-clauses [
   { begin
     ((zero? boolean) <- eq (n integer) (0 literal))
     (break-unless (zero? boolean))