On Nov 4, 2005, at 3:29 AM, Nikodemus Siivola wrote:
> On Fri, 4 Nov 2005, James Y Knight wrote:
>> So I'd like to make constantp return t more often, in particular,
>> cases like
>> It seems like the nicest way to do that may be to IR1-compile the
>> argument, and then check the IR1 output to see if it looks like a
>> constant function.
> Sounds like a shitload of work for CONSTANTP. ;-)
> For testing the constantness of complex form I think an evaluator-like
> approach might be better:
> 1) macroexpand the form
> 2) if a function call, is this function foldable?
> 3) if foldable, are all the arguments constant?
> Much less work then compiling the form, and arguably cleaner too.
The reason I started exploring this in the first place is that we
(ITA software) have an constant folder, our own foldable function
database, and part of an evaluator. Yes, it's insane, and I'd really
like to get rid of it. To do so, however, I need (for efficiency) a
constantp that returns t as often as it can, so that we can do more
work at compile time and less work at runtime when some expressions
I actually originally tried something similar to what you posted, but
it's not really that simple, if you want constantp to be good. In
particular, it should support lambda reduction, inlined functions,
all the special forms like if, progn, the, let, etc., in short, the
stuff the compiler does. It is of course acceptable from a
correctness standpoint to only handle a small subset of expressions,
and juts return nil for the rest, but for performance it should
return t as often as possible.
SBCL already has a compiler which knows perfectly well how to do
constant-folding, and making constantp expose the existing builtin
constant folding was almost trivial, except for the horribleness of
the million special variables and my complete lack of familiarity
with the compiler.
An outer constantp which starts like the old one, only deferring to
the compiler version when it finds a non-quote list would very likely
be a good idea.