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

From: Curtis Warren (cwarren89 at gmail.com)
Date: Mon Jul 13 19:29:43 EDT 2009

On Mon, Jul 13, 2009 at 3:36 PM, Marco Morazan<morazanm at gmail.com> wrote:
> 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

Define the structure as #:mutable
(http://docs.plt-scheme.org/reference/define-struct.html). Then use
set-nbr-list!.


Posted on the users mailing list.