Hello. I have the following:
>
> (define alist '(("a" . 1) ("b" . 2) ("c" . 3)))
> (define anentry (assoc "b" alist))
> anentry
'("b" . 2)
> (set-cdr! y 3)
Error: exception
(set-cdr! '("b" . 2) 3)
1>
But the following works fine
>
> (define alist (list (cons "a" 1) (cons "b" 2) (cons "c" 3)))
> (set! y (assoc "b" alist))
> y
'("b" . 2)
> (set-cdr! y 3)
> y
'("b" . 3)
> alist
'(("a" . 1) ("b" . 3) ("c" . 3))
>
I'm using scsh 0.6.2. I have tested this with other interpreters and
both work fine. Is this a known bug? Am I doing something wrong?
Saludos
--
+-----------------
| Francisco Vides Fernández <p...@dedaloingenieros.com>
| Director técnico.
| Teléfono fijo: 952 60 29 59
| Teléfono móvil: 661 67 32 73
| Fax: 952 60 29 59
| Dédalo Ingenieros http://www.dedaloingenieros.com/
| PGP: http://pgp.rediris.es:11371/pks/lookup?op=index&search=0x605ecbab
+------
Sorry, my previous example was wrong. I meant this:
>
> (define alist '(("a" . 1) ("b" . 2) ("c" . 3)))
> (define anentry (assoc "b" alist))
> anentry
'("b" . 2)
> (set-cdr! anentry 3)
Error: exception
(set-cdr! '("b" . 2) 3)
1>
But the following works fine
>
> (define alist (list (cons "a" 1) (cons "b" 2) (cons "c" 3)))
> (set! y (assoc "b" alist))
> anentry
'("b" . 2)
> (set-cdr! anentry 3)
> anentry
> Error: exception
> (set-cdr! '("b" . 2) 3)
>
> But the following works fine
[...]
> I'm using scsh 0.6.2. I have tested this with other interpreters and
> both work fine. Is this a known bug? Am I doing something wrong?
In the first case, you are trying to mutate a constant object. The Scheme
report says <http://www.swiss.ai.mit.edu/~jaffer/r5rs_5.html#SEC22>
In many systems it is desirable for constants (i.e. the values of
literal expressions) to reside in read-only-memory. To express this, it
is convenient to imagine that every object that denotes locations is
associated with a flag telling whether that object is mutable or
immutable. In such systems literal constants and the strings returned by
symbol->string are immutable objects, while all objects created by the
other procedures listed in this report are mutable. It is an error to
attempt to store a new value into a location that is denoted by an
immutable object. (R5RS section 3.4 Storage Model)
See also the section on literal expressions.
rthappe
Ok, thanks a lot!
>>>>> "RT" == RT Happe <rth...@web.de> writes:
RT> On Tue, 1 Apr 2003, Francisco Vides Fernandez wrote:
>> Error: exception (set-cdr! '("b" . 2) 3)
>>
>> But the following works fine
RT> [...]
>> I'm using scsh 0.6.2. I have tested this with other interpreters
>> and both work fine. Is this a known bug? Am I doing something
>> wrong?
RT> In the first case, you are trying to mutate a constant object.
RT> The Scheme report says
RT> <http://www.swiss.ai.mit.edu/~jaffer/r5rs_5.html#SEC22>
RT> In many systems it is desirable for constants (i.e. the values
RT> of literal expressions) to reside in read-only-memory. To express
RT> this, it is convenient to imagine that every object that denotes
RT> locations is associated with a flag telling whether that object
RT> is mutable or immutable. In such systems literal constants and
RT> the strings returned by
symbol-> string are immutable objects, while all objects created by
symbol-> the
RT> other procedures listed in this report are mutable. It is an
RT> error to attempt to store a new value into a location that is
RT> denoted by an immutable object. (R5RS section 3.4 Storage Model)
RT> See also the section on literal expressions.
RT> rthappe