* Goops: Setting Immutible Classes?
@ 2017-10-06 6:00 Christopher Howard
2017-10-06 6:24 ` Mark H Weaver
2017-10-06 12:55 ` Thompson, David
0 siblings, 2 replies; 4+ messages in thread
From: Christopher Howard @ 2017-10-06 6:00 UTC (permalink / raw)
To: Guile User Mailing List
[-- Attachment #1: Type: text/plain, Size: 514 bytes --]
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)?
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...?
--
https://www.debian.org/
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Goops: Setting Immutible Classes?
2017-10-06 6:00 Goops: Setting Immutible Classes? Christopher Howard
@ 2017-10-06 6:24 ` Mark H Weaver
2017-10-06 15:46 ` Christopher Allan Webber
2017-10-06 12:55 ` Thompson, David
1 sibling, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2017-10-06 6:24 UTC (permalink / raw)
To: Christopher Howard; +Cc: Guile User Mailing List
Christopher Howard <christopher.howard@qlfiles.net> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Goops: Setting Immutible Classes?
2017-10-06 6:00 Goops: Setting Immutible Classes? Christopher Howard
2017-10-06 6:24 ` Mark H Weaver
@ 2017-10-06 12:55 ` Thompson, David
1 sibling, 0 replies; 4+ messages in thread
From: Thompson, David @ 2017-10-06 12:55 UTC (permalink / raw)
To: Christopher Howard; +Cc: Guile User Mailing List
On Fri, Oct 6, 2017 at 2:00 AM, Christopher Howard
<christopher.howard@qlfiles.net> wrote:
> 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)?
I'm not too familiar with the meta-object protocol, but this sounds
like a case where you could make a new metaclass that supports
immutable slot setters. See Section 8.11 in the manual.
- Dave
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Goops: Setting Immutible Classes?
2017-10-06 6:24 ` Mark H Weaver
@ 2017-10-06 15:46 ` Christopher Allan Webber
0 siblings, 0 replies; 4+ messages in thread
From: Christopher Allan Webber @ 2017-10-06 15:46 UTC (permalink / raw)
To: Mark H Weaver; +Cc: Guile User Mailing List
Mark H Weaver writes:
> Christopher Howard <christopher.howard@qlfiles.net> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-06 15:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-06 6:00 Goops: Setting Immutible Classes? Christopher Howard
2017-10-06 6:24 ` Mark H Weaver
2017-10-06 15:46 ` Christopher Allan Webber
2017-10-06 12:55 ` Thompson, David
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).