Comment 1 for bug 722552

Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

(LIST 1 2) is not a constant -- it must evaluate to a freshly consed list every time. SBCL already handles constant function calls (where every argument is a constant), and the function can be safely constant-folded. If something isn't getting recognized, it is because either there is no DEFKNOWN for it, or the DEFKNOWN doesn't mark the function as foldable.

The examples where we currently say NIL from the CLHS page are:

CL-USER> (constantp '(eql x x))
NIL
CL-USER> (constantp '(typep x 'nil))
NIL
CL-USER> (constantp '(typep x 't))
NIL
CL-USER> (constantp '(values this-is-a-constant))
NIL
CL-USER> (constantp '(values 'x 'y))
NIL
CL-USER> (constantp '(let ((a '(a b c))) (+ (length a) 6)))
NIL

Note that we already handle things like IF: (constantp '(if t 'constant variable)) => T

People interested in adding support for VALUES and LET should look in src/compiler/constantp.lisp -- it contains a ...partial... partial evaluator.

Supporting (TYPEP X T) and (TYPEP X NIL) is possible, but needs a special hack.