[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Goops: Setting Immutible Classes?
From: |
Christopher Allan Webber |
Subject: |
Re: Goops: Setting Immutible Classes? |
Date: |
Fri, 06 Oct 2017 10:46:53 -0500 |
User-agent: |
mu4e 0.9.18; emacs 25.3.1 |
Mark H Weaver writes:
> Christopher Howard <address@hidden> writes:
>
>> Hi, is the a way I could use goops such that I the classes are non-
>> mutating, but have setters that simply return a new instance of the
>> class (instead of modifying the original)?
>
> We provide such a mechanism for SRFI-9 Records. Search for "Functional
> Setters" in section 6.6.16 (SRFI-9 Records) of the Guile manual.
>
>> I suppose I could simply use define-method to create setter methods
>> which create a new instance of the object; but that would get rather
>> complicated, wouldn't it, if the object had superclasses? So I need
>> some kind of shallow copy mechanism for the whole object, or a chained
>> copy mechanism...?
>
> For GOOPS classes, take a look at the built-in 'shallow-clone' generic
> function. It is described in section 8.10 (GOOPS Object Miscellany).
>
> Mark
See also
https://lists.gnu.org/archive/html/guile-user/2017-01/msg00030.html
which includes both a slot-fset approach and a clone macro. Personally
I've come to like the clone macro more over time.