summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-01-20 07:22:09 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-01-20 07:22:09 -0800
commita92cd39b8c12305a4e7092afe418c6006dbebeb5 (patch)
tree195f6d02ccb835cee9603f89f5182b5445e70414
parent9a2f9df335393284f6af2d95dbd65cb606792ad8 (diff)
downloadtxr-a92cd39b8c12305a4e7092afe418c6006dbebeb5.tar.gz
txr-a92cd39b8c12305a4e7092afe418c6006dbebeb5.tar.bz2
txr-a92cd39b8c12305a4e7092afe418c6006dbebeb5.zip
compiler: bug in new and expansion.
* /share/txr/stdlib/compiler.tl (expand-and): The case with @(true-const-p) is wrongly ordered with respect to (and @a). The problem is that @rest can match a null terminator, and then we wrongly consume the constant; i.e. (and 42) calls (expand-and ^(and)) yielding t. Also, we eliminate the (and @a @b) case, because it is redundant with respect to (and @a . @rest). We adjust the latter to just output (if ...). And, lo and behold, now the function's cases map 1:1 to the ones in reduce-or. In fact reduce-or was originally produced from expand-and. I debugged it thoroughly, but neglected to backport to expand-and.
-rw-r--r--share/txr/stdlib/compiler.tl5
1 files changed, 2 insertions, 3 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl
index f62f5fb1..ff769a0f 100644
--- a/share/txr/stdlib/compiler.tl
+++ b/share/txr/stdlib/compiler.tl
@@ -1280,11 +1280,10 @@
(defun expand-and (form)
(match-case form
((and) t)
+ ((and @a) a)
((and @(true-const-p) . @rest) (expand-and ^(and ,*rest)))
((and nil . @rest) nil)
- ((and @a) a)
- ((and @a @b) ^(if ,a ,b))
- ((and @a . @rest) (expand-and ^(and ,a ,(expand-and ^(and ,*rest)))))
+ ((and @a . @rest) ^(if ,a ,(expand-and ^(and ,*rest))))
(@else else)))
(defun flatten-or (form)