wanted: smarter CONSTANTP
Bug #722552 reported by
Roman Marynchak
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Won't Fix
|
Low
|
Unassigned |
Bug Description
It will be nice to handle all the implementation-
http://
Moreover, it will be nice to have (constantp '(list 1 2)) -> T. This case is useful for LOOP and for LOOP-CONSTANT-
Does Launchpad have something like "issue children"? I feel that there may be many patches for this single issue, and it is better to split it.
To post a comment you must log in.
(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)) a-constant) )
NIL
CL-USER> (constantp '(typep x 'nil))
NIL
CL-USER> (constantp '(typep x 't))
NIL
CL-USER> (constantp '(values this-is-
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.