I am trying to understand something interesting that happens on the diagram:
(define last-pair (lambda (x) (if (null? (cdr x)) x (last-pair (cdr x)))))
When I defined foo this way:
(define foo (lambda () (let ((s (list 'he 'said:))) (set-cdr! (last-pair s) (list 'ha 'ha)) s)))
and run foo 3 times, I got:
(he said: ha ha) (he said: ha ha) (he said: ha ha)
But when I defined foo this way:
(define foo (lambda () (let ((s '(he said:))) (set-cdr! (last-pair s) (list 'ha 'ha)) s)))
and run foo 3 times, I got:
(he said: ha ha) (he said: ha ha ha ha) (he said: ha ha ha ha ha ha)
But why? My first thought was that we always build a new list in the first foo , but not in the second. But I did not understand how this works. The circuit defines the address in the second foo so what? Is it defined as a list also in the second foo? or symbol?
Thanks.
source share