From: Jan Nieuwenhuizen <janneke@gnu.org>
To: Christopher Allan Webber <cwebber@dustycloud.org>
Cc: Guile user <guile-user@gnu.org>
Subject: Re: GOOPS functional setter
Date: Fri, 13 Jan 2017 22:33:05 +0100 [thread overview]
Message-ID: <87bmva7ii6.fsf@gnu.org> (raw)
In-Reply-To: <871sw6g4je.fsf@dustycloud.org> (Christopher Allan Webber's message of "Fri, 13 Jan 2017 13:09:57 -0600")
Christopher Allan Webber writes:
> I guess I never sent this to this list. Here's a functional setter for
> GOOPS classes.
Hah! Just this week I have been wondering the perceived absense of
functional setters (and figured I *must* have missed something
somewhere) and wrote
--8<---------------cut here---------------start------------->8---
(define ((identity-initializer o) name)
(list (symbol->keyword name) (slot-ref o name)))
(define-method (clone o . setters)
(let* ((class (class-of o))
(slots (class-slots class))
(names (map slot-definition-name slots))
(initializers (map (identity-initializer o) names))
(keywords (filter keyword? setters))
(initializers (filter (lambda (i) (not (memq (car i) keywords))) initializers))
(initializers (append (apply append initializers) setters))
(arguments (cons class initializers)))
(apply make arguments)))
--8<---------------cut here---------------end--------------->8---
Usage:
(clone o #:slot <VALUE> ...)
Greetings,
Jan
--
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl
prev parent reply other threads:[~2017-01-13 21:33 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
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 [this message]
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=87bmva7ii6.fsf@gnu.org \
--to=janneke@gnu.org \
--cc=cwebber@dustycloud.org \
--cc=guile-user@gnu.org \
/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).