I have a function that produces constant results when given constant
arguments, and I would like to make CONSTANTP aware of that, so that:
(constantp '(my-function 5 8)) -> T
The CLHS seems to say the treatment of that kind of expression is
implementation-dependant. I'm using CMUCL; I looked into the docs and
found only:
(declaim (ext:constant-function my-function))
which looks like it could have helped, but CONSTANTP doesn't seem to care.
(constantp '(+ 2 3))
gives NIL on CMUCL, so I'm not expecting much...
Any ideas?
PS: I'll also take ideas about achieving this:
(constantp '(+ 2 3)) -> T
Philippe Lorin <············@gmail.com> writes:
> I have a function that produces constant results when given constant
> arguments, and I would like to make CONSTANTP aware of that, so that:
> (constantp '(my-function 5 8)) -> T
>
> The CLHS seems to say the treatment of that kind of expression is
> implementation-dependant. I'm using CMUCL; I looked into the docs and
> found only:
> (declaim (ext:constant-function my-function))
> which looks like it could have helped, but CONSTANTP doesn't seem to care.
>
> (constantp '(+ 2 3))
> gives NIL on CMUCL, so I'm not expecting much...
>
> Any ideas?
>
> PS: I'll also take ideas about achieving this:
> (constantp '(+ 2 3)) -> T
A core functionnality could be implemented as simply as:
- keeping a list of pure functions in CL.
- walking the form and checking that only literals
and pure functions are used.
The next step could be to add processing of the environment, accepting:
- constant variables,
- bindings with constant forms.
Finally, you could implement a pure function predicate to determine if
a user defined function is pure.
--
__Pascal_Bourguignon__ _ Software patents are endangering
() ASCII ribbon against html email (o_ the computer industry all around
/\ 1962:DO20I=1.100 //\ the world http://lpf.ai.mit.edu/
2001:my($f)=`fortune`; V_/ http://petition.eurolinux.org/