From a92cd39b8c12305a4e7092afe418c6006dbebeb5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 20 Jan 2021 07:22:09 -0800 Subject: 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. --- share/txr/stdlib/compiler.tl | 5 ++--- 1 file 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) -- cgit v1.2.3