From bfce69c0af7c48add464ab1233bb48d0e4d6059f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 6 Apr 2023 16:08:51 -0700 Subject: 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. --- stdlib/ifa.tl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'stdlib') 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)) -- cgit v1.2.3