I was trying to define a data structure initialization function like '(() ()), so that I can generate many of it later.
Right after I defined it, the init function works expectedly. But after I use set-car! inside a (let* ...) function call, the behavior of (init) changed.
My question is how to explain this behavior?
; define init func
(define (init)
(display "initializing goal space...")
(newline)
'(() ())
)
; call init func
(init)
; use set-car! in (let* ...)
(let*
((x (init)))
(display x)
(newline)
(set-car! x (list 'foo))
(display x)
(newline)
)
; call init func again
(init)
The output log in DrScheme, lang = Textual (MzScheme, include R5RS)
Welcome to DrScheme, version 372 [3m].
Language: Textual (MzScheme, includes R5RS).
initializing goal space...
(() ())
initializing goal space...
(() ())
((foo) ())
initializing goal space...
((foo) ())
>