Immutability of literals?
Author Message
Immutability of literals?

In assorted places in r5rs (among them 3.4) it says that literals are
immutable. Having used Plt and Guile, both of them seem to allow

(define k '(a . b))
(set-car! k 'something)

whereupon k would be (something . b). Does this contravene the spec or am
I missing something?

Furthermore, I am confused by the notion in Section 6.3.6 that "vector
constants must be quoted". Does this mean that

#(a b c)

at the input prompt would be immutable (because it is a literal) or
mutable (because, not being quoted, it cannot be constant)?

For that matter, why do vectors have to be quotes when no other
self-evaluating forms (chars, numbers etc) have to?

And finally, how much of lists and vectors that have been quasiquoted
(with bits unquoted in them) have to be immutable? e.g.

`(a ,b c d)

Should the (c d) sublist still be immutable? What about the cons cell
containing symbol a (which has a literal car and a non-literal cdr)? How
does this apply to vectors?

Thank you

Sat, 06 Jul 2002 03:00:00 GMT
Immutability of literals?

Quote:

>In assorted places in r5rs (among them 3.4) it says that literals are
>immutable. Having used Plt and Guile, both of them seem to allow

>(define k '(a . b))
>(set-car! k 'something)

>whereupon k would be (something . b). Does this contravene the spec or am
>I missing something?

It contravenes the spec.  However, the spec doesn't require implementations
to detect this error, so they can allow the modification.

This clause in the spec allows implementations to combine similar literals,
e.g.

(define k '(a . b))
(define l '(a . b))
(set-car! k 'something)
(car l) => something  !!

The implementation isn't violating the spec by allowing the sett-car!; the
programmer is violating the spec by using it.

Quote:
>Furthermore, I am confused by the notion in Section 6.3.6 that "vector
>constants must be quoted". Does this mean that

>#(a b c)

>at the input prompt would be immutable (because it is a literal) or
>mutable (because, not being quoted, it cannot be constant)?

You're confusing two issues.  When the spec says that they must be quoted,
it means that it's not defining what happens when you try to evaluate a
vector constant (quoting prevents evaluation).  Entering it without quoting
is an error.

Quote:
>For that matter, why do vectors have to be quotes when no other
>self-evaluating forms (chars, numbers etc) have to?

What it's doing is pointing out that vectors aren't self-evaluating.
According to section 7.1.3 of R5RS:

<self-evaluating> ---> <boolean> | <number> | <character> | <string>

Notice that vectors aren't listed there.

Quote:
>And finally, how much of lists and vectors that have been quasiquoted
>(with bits unquoted in them) have to be immutable? e.g.

>`(a ,b c d)

>Should the (c d) sublist still be immutable? What about the cons cell
>containing symbol a (which has a literal car and a non-literal cdr)? How
>does this apply to vectors?

Good question.  The section on literal expressions says that the only way
to create them is with self-evaluating or quoted expressions, and doesn't
mention quasiquotation.  So it seems like this implies that quasiquote
doesn't create literals.

--