From: Christopher Allan Webber <cwebber@dustycloud.org>
To: tomas@tuxteam.de
Cc: guile-user@gnu.org
Subject: Re: GOOPS functional setter
Date: Fri, 13 Jan 2017 20:11:28 -0600 [thread overview]
Message-ID: <87vatie6gf.fsf@dustycloud.org> (raw)
In-Reply-To: <20170113205646.GB10416@tuxteam.de>
tomas@tuxteam.de writes:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Fri, Jan 13, 2017 at 01:09:57PM -0600, Christopher Allan Webber wrote:
>> I guess I never sent this to this list. Here's a functional setter for
>> GOOPS classes.
>>
>> Maybe nobody else would use it, but I've used it in a couple of projects
>> now, so figure I might as well share.
>>
>> This is LGPLv3+. Feel free to use.
>>
>> ==================================================
>>
>> ;; By Christopher Allan Webber, LGPLv3+; adapted from shallow-clone in GOOPS
>> (use-modules (oop goops))
>>
>> (define-method (slot-fset (self <object>) slot-name value)
>> "Return a new copy of SELF, with all slots preserved except SLOT-NAME
>> set to VALUE."
>
> (from the peanut gallery)
>
> I understand now what it does, but the name "slot-fset" would confuse the heck
> of me. Why not something like "clone" or perhaps "clone*"?
>
> regards
> - -- tomás
I think cloning isn't as clear; what we want is something that's the
same as the previous instance of the object, but with one field changed.
Clone makes it sound the same, but the goal is change without affecting
the original. It's attempting to be the same as slot-set! but
functional, hence slot-fset. Again, inspired by set-field and
set-fields from (srfi srfi-9 gnu).
However, I'm open to another name, if someone has something better...
(Also, it would even be nicer if it were possible to make the new
instance without copying every field manually as I did here. It would
be interesting if there were a metaclass that was smarter about slot
allocation and used some functional structure so that we didn't need to
iterate through every field just to change the one slot. I'm not sure
how hard that would be to do, or if it would be of significant benefit
in the end.)
next prev parent reply other threads:[~2017-01-14 2:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-13 19:09 GOOPS functional setter Christopher Allan Webber
2017-01-13 20:56 ` tomas
2017-01-14 2:11 ` Christopher Allan Webber [this message]
2017-01-14 10:08 ` tomas
2017-01-14 17:25 ` Arne Babenhauserheide
2017-01-14 21:16 ` Christopher Allan Webber
2017-01-15 9:31 ` tomas
2017-01-13 21:33 ` Jan Nieuwenhuizen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vatie6gf.fsf@dustycloud.org \
--to=cwebber@dustycloud.org \
--cc=guile-user@gnu.org \
--cc=tomas@tuxteam.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).