diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-11-24 22:44:42 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-11-24 22:51:03 -0800 |
commit | c1b2f17fcf02ce40aaf345880d928f6ee540f80e (patch) | |
tree | 8f03505b49f46af0ebbcf1db2c2cd56d60d970ef | |
parent | 371925c3d55486745f44109d19e9c7b674171f1d (diff) | |
download | mu-c1b2f17fcf02ce40aaf345880d928f6ee540f80e.tar.gz |
323 - function clauses
You can now call 'def' on a function name multiple times. Each time the instructions you provide are *prepended* to any existing instructions. One important use for this is when you define a new type and need to support it in all your generic methods. Now you can keep all those extensions in one place, near the definition of the type. To redefine a function, use 'def!'.
-rw-r--r-- | mu.arc | 8 | ||||
-rw-r--r-- | mu.arc.t | 27 |
2 files changed, 33 insertions, 2 deletions
diff --git a/mu.arc b/mu.arc index aaab580a..1e99adab 100644 --- a/mu.arc +++ b/mu.arc @@ -1067,11 +1067,15 @@ (each (op . rest) forms (case op ; syntax: def <name> [ <instructions> ] - def + ; don't apply our lightweight tools just yet + def! (let (name (_make-br-fn body)) rest (assert (is 'make-br-fn _make-br-fn)) - ; don't apply our lightweight tools just yet (= function*.name body)) + def + (let (name (_make-br-fn body)) rest + (assert (is 'make-br-fn _make-br-fn)) + (= function*.name (join body function*.name))) ; syntax: before <label> [ <instructions> ] ; diff --git a/mu.arc.t b/mu.arc.t index caace661..8534e9f4 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -2807,4 +2807,31 @@ ((1 integer) <- copy (0 literal)))) (prn "F - before/after can come after the function they need to modify")) +(reset) +(new-trace "multiple-defs") +(add-code '((def f1 [ + ((1 integer) <- copy (0 literal)) + ]) + (def f1 [ + ((2 integer) <- copy (0 literal)) + ]))) +(freeze-functions) +(if (~iso function*!f1 + '(((2 integer) <- copy (0 literal)) + ((1 integer) <- copy (0 literal)))) + (prn "F - multiple 'def' of the same function add clauses")) + +(reset) +(new-trace "def!") +(add-code '((def f1 [ + ((1 integer) <- copy (0 literal)) + ]) + (def! f1 [ + ((2 integer) <- copy (0 literal)) + ]))) +(freeze-functions) +(if (~iso function*!f1 + '(((2 integer) <- copy (0 literal)))) + (prn "F - 'def!' clears all previous clauses")) + (reset) ; end file with this to persist the trace for the final test |