[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: define-constant and define-integrable



Duke Briscoe asks:

>I have a question about the effect of the "early binding" forms on
>compilation.  What do the following two forms do, and how would they
>differ in their effects?
>
>(define-integrable (%%div x y)
>    (if (and (integer? x)
>             (integer? y))
>        (quotient x y)
>        (/ x y) ))
>
>compared to
>
>(define-constant %%div
>  (lambda (x y)
>    (if (and (integer? x)
>             (integer? y))
>        (quotient x y)
>        (/ x y) )))

Expanding forms similar to these shows the following:

   > (pp (fully-expand-macro '(define-integrable (foo x) (+ x 5))))

   (BLOCK (DECLARE CONSTANT FOO)
          (DEFINE-VARIABLE-VALUE FOO
                                 (NAMED-LAMBDA FOO (X) (+ X 5))))

   > (pp (fully-expand-macro '(define-constant foo (lambda (x) (+ x 5)))))

   (BLOCK (DECLARE CONSTANT FOO)
          (DEFINE-VARIABLE-VALUE FOO (LAMBDA (X) (+ X 5))))

There seems to be no difference between the two other than the name being
given to the LAMBDA in the DEFINE-INTEGRABLE case.  In fact, looking at the
source (MACROS.T) shows that DEFINE-INTEGRABLE is defined to be the same as
DEFINE-CONSTANT, so the only difference in the cases above is from defining 
a symbol to be a LAMBDA vs. defining a function of arguments to be a body 
(ie, the second uses NAMED-LAMBDA instead of LAMBDA).


Bruce