[plt-scheme] Re: mutating fields [was: set-car! in EOPL language]

From: Marco Morazan (morazanm at gmail.com)
Date: Mon Jul 13 16:36:12 EDT 2009

Actually, let me refine my question. Given a defined datatype, say:

(define-datatype node node?
  (a-node
   (n  symbol?)
   (func-list (list-of extended-def?))
   (nbr-list (list-of node?))
   (free-var vector?)))

How can I mutate the fields of an instance of a node? Something like:

...
(cases node (car nodelist)
                 (a-node (n fl neighs v)
                         (set! neighs node-neighbors)))

does not do the trick, of course, because it is neighs that is mutated
(and not (car nodelist)). Is there anything like:

(set-node-nbr-list! (car nodelist) node-neighbors) ?

Thanks,

Marco


On Mon, Jul 13, 2009 at 3:49 PM, Marco Morazan<morazanm at gmail.com> wrote:
> Dear All,
>
> On this bit of code:
>
> (cases node (car nodelist)
>                 (a-node (n fl neighs v)
>                         (set-car! nodelist (a-node n fl node-neighbors v))))
>
> where nodelist is a list of nodes (a defined datatype), I get this error:
>
> Welcome to DrScheme, version 4.2 [3m].
> Language: Essentials of Programming Languages (3rd ed.); memory limit:
> 128 megabytes.
> . . reference to undefined identifier: set-car!
>>
>
> Why is set-car! undefined? Solution?
> --
>
> Cheers,
>
> Marco
>



-- 

Cheers,

Marco


Posted on the users mailing list.