Subject: broken set! in iteration

From: Alírio Eyng <[email-masked]>
Date: Sat, 21 Jun 2014 01:25:56 +0000

I can't see why the second code doesn't work like the first:

(use-modules (srfi srfi-1))
(define D '(((3 4))))
(let ((r 1))
       (set! D (append D '(())))
       (display D)(newline)
       (set-car! (drop D r) (car (drop D (- r 1)))))
(let ((r 2))
       (set! D (append D '(())))
       (display D)(newline)
       (set-car! (drop D r) (car (drop D (- r 1)))))
output:
(((3 4)) ())
(((3 4)) ((3 4)) ())

(use-modules (srfi srfi-1))
(define D '(((3 4))))
(map (lambda (r)
       (set! D (append D '(())))
       (display D)(newline)
       (set-car! (drop D r) (car (drop D (- r 1)))))
     '(1 2))
output:
(((3 4)) ())
(((3 4)) ((3 4)) ((3 4)))

guile (GNU Guile) 2.0.11
i686-pc-linux-gnu