diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-04-06 16:08:51 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-04-06 16:08:51 -0700 |
commit | bfce69c0af7c48add464ab1233bb48d0e4d6059f (patch) | |
tree | 38ed9742887f89cc85a1acd2972af1607d495b77 | |
parent | 8bde000ce358d849a2b5a1c2a88b3be296bfdb6d (diff) | |
download | txr-bfce69c0af7c48add464ab1233bb48d0e4d6059f.tar.gz txr-bfce69c0af7c48add464ab1233bb48d0e4d6059f.tar.bz2 txr-bfce69c0af7c48add464ab1233bb48d0e4d6059f.zip |
conda/condlet: fix broken scope.
Contrary to the documentation, the later clauses of a condlet
have the earlier clause variables in scope.
* stdlib/ifa.tl (sys:if-to-cond): Change to different,
non-nesting expansion strategy. We lose the cond-oper
parameter.
(conda, condlet): Drop second parameter from calls
to if-to-cond.
-rw-r--r-- | stdlib/ifa.tl | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/stdlib/ifa.tl b/stdlib/ifa.tl index e2c35f14..c16d8345 100644 --- a/stdlib/ifa.tl +++ b/stdlib/ifa.tl @@ -69,15 +69,16 @@ (defmacro whena (test . body) ^(ifa ,test (progn ,*body))) -(defun sys:if-to-cond (f if-oper cond-oper pairs) - (tree-case pairs - (((test . forms) . rest) ^(,if-oper ,test (progn ,*forms) - (,cond-oper ,*rest))) - (() ()) - (else (compile-error f "bad syntax: ~s" else)))) +(defun sys:if-to-cond (f if-oper pairs) + (with-gensyms (res) + ^(let (,res) + (or ,*(collect-each ((c pairs)) + (mac-param-bind f (test . forms) c + ^(,if-oper ,test (progn (set ,res (progn ,*forms)) t))))) + ,res))) (defmacro conda (:form f . pairs) - (sys:if-to-cond f 'ifa 'conda pairs)) + (sys:if-to-cond f 'ifa pairs)) (defmacro condlet (:form f . pairs) - (sys:if-to-cond f 'iflet 'condlet pairs)) + (sys:if-to-cond f 'iflet pairs)) |