Shouldn't this be constant space? 
Author Message
 Shouldn't this be constant space?

   Date: Sun, 5 Jun 1994 03:19:04 GMT

   I typed in the following functions straight out of the R4RS
   report [p. 28]

     (define a-stream
       (letrec ((next
                 (lambda (n)
                   (cons n (delay (next (+ n 1)))))))
         (next 0)))

   [...]

   So 'nth' should be tail-recursive, right?  If so, then why do two
   different implementations cause my machine to swap itself to death
   while a third segfaults on calling

    (nth a-stream 1000000) ?

NTH is tail-recursive, but unfortunately the variable A-STREAM is
holding on to the head of the stream.  Because of this the garbage
collector can't reclaim any of that stream, which is constantly
growing longer as you pull at the end of it.

I don't know why you got a segmentation violation in that one
implementation -- that sounds like a serious bug in the memory
management.



Thu, 21 Nov 1996 13:33:18 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. delelting space if it's one space

2. Shouldn't there be an Exit Block Statement in Smalltalk

3. Help! Deleted files I shouldn't have

4. Shouldn't I do so? [copyright law]

5. Coding challenge: Space-separated constants

6. wanted: pretty printer w/. constant space usage

7. Constant-space guarantees in R5RS

8. Solution with constant space -- lisp exercise

9. shouldn't STOP?

10. Mistery: JGE taken while it shouldn't have been

11. Mystery: JGE taken but it shouldn't have happened

12. instead of C++ shouldn't ms have used masm for win95

 

 
Powered by phpBB® Forum Software