RE: bug? (I think so)

From: Eduard C Hoenkamp <edh_at_ergolab2.psych.kun.nl>
Date: Thu, 7 Nov 1996 11:57:18 +0100

simplified version of the question:
(define (split1 lst)
  (cond ((null? lst) '(()))
        (else
         (let ((sf (split1 (cdr lst))))
           (set-car! sf (cons (car lst) (car sf)))
           sf))))

Try this with (split1 '(a)) severel times, and you get
(a) (a a) (a a a) etc. Whereas if you use (list (list)) instead
of '(()) you will get (a) every time.

1. (eq? '() (list)) -> #t
   (eq? '(()) (list (list))) -> #f

2. according to R4R (list obj) returns a NEWLY allocated list of its
arguments (see page 17). So in the (list(list)) case you know that
you have a new object with each call to split1

3. Apperently the '(()) is created at definition time, and then
destructively changed with each call to split1. So this would be
like defining

(define (split1 lst)
  (define double-nil '(()))
  (cond ((null? lst) double-nil)
...

To summarize, I can see why this happens, but I too, would call it a bug.
Edward.
Received on Thu Nov 07 1996 - 11:57:07 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST