Please take a look at R5RS, which says that
it is an error to alter a constant (i.e. the value of a literal expression) using a mutation procedure like
set-car!
orstring-set!
.
So '(1)
and (list 1)
are not exactly the same thing: when you are intended to build some data that would be mutated in the future, don't use quotations.
If you try to do this:
(define (f) (list 1))
(define (g) '(1))
(display (eq? (f) (f)))(newline)
(display (eq? (g) (g)))(newline)
You will get:
#f
#t
This is suggesting that f
will make a list whenever called. But g
will treat its list '(1)
as a constant and that list is allocated only once, no matter how many times it is called.