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

Re: consing with +



At 10:13 AM 9/2/93 -0400, Mark.Perlin@J.GP.CS.CMU.EDU wrote:
>Since + has &rest arguments, it may entail consing.  I'm certainly getting
>enough garbage collection in inner numerical loops to suggest this.
>Questions:
>
>(1) Does +, indeed, entail consing?  (If not, then DOTIMES must be the
>culprit, which is even less likely.) 
>
>(2) If (1) is true, is there any way to force + to be a nonconsing binary
>operator? 

+ does not cons due to its rest argument. If the result is
other than a fixnum or short float, however, storage for the result
will be consed.

Example (I used LET below to prevent the addition from being done
at compile time):

? (time (let ((x 1)
              (y 2))
          (+ x y)))
(LET ((X 1) (Y 2)) (+ X Y)) took 0 milliseconds (0.000 seconds) to run.
3
? (time (let ((x 1.2s0)
              (y 3.4s0))
          (+ x y)))
(LET ((X 1.2S0) (Y 3.4S0)) (+ X Y)) took 0 milliseconds (0.000 seconds) to run.
4.6000004S0
? (time (let ((x 1.2)
              (y 3.4))
          (+ x y)))
(LET ((X 1.2) (Y 3.4)) (+ X Y)) took 0 milliseconds (0.000 seconds) to run.
 8 bytes of memory allocated.
4.6
? (time (let ((x (expt 2 32))
              (y (expt 2 33)))
          (+ x y)))
(LET ((X (EXPT 2 32)) (Y (EXPT 2 33))) (+ X Y)) took 0 milliseconds (0.000 seconds) to run.
 16 bytes of memory allocated.
12884901888
? (time (let ((x 1/2)
              (y 2/3))
          (+ x y)))
(LET ((X 1/2) (Y 2/3)) (+ X Y)) took 0 milliseconds (0.000 seconds) to run.
 16 bytes of memory allocated.
7/6
?