Re: Bug?

From: Raymond Toy <toy_at_rtp.ericsson.se>
Date: Thu, 17 Oct 1996 11:43:32 -0400

>>>>> "David" == David Fox <fox_at_graphics.cs.nyu.edu> writes:


    David> Using snow 3.1 on my Linux box the following function produces
    David> different results each time I run it on (split1 (string->list
    David> "ab/cd"))

    David> (define (split1 lst)
    David> (cond ((null? lst) '(()))
    David> ((eq? (car lst) #\/) (cons () (split1 (cdr lst))))
    David> (else
    David> (let ((sf (split1 (cdr lst))))
    David> (set-car! sf (cons (car lst) (car sf)))
    David> sf))))

    David> If I replace "'(())" with "(list (list))" it works correctly.

This last statement is the clue. You've made self-modifying code.
Apparently set-car! ends up being applied to '(()). This ends up
changing your source code. Try (split1 '()) after running your test a
couple of times. You'll see that split1 does not return '(()).

I don't know if this is a bug, but in On Lisp, by P. Graham, there are
several examples of unintentional self-modifying macros. The result
is something like you see here---every invocation produces something
different. His solution was not to do that, or to generate new lists
every time, just as your solution above does.

Ray
Received on Thu Oct 17 1996 - 17:45:00 CEST

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