[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GOOPS functional setter
From: |
Jan Nieuwenhuizen |
Subject: |
Re: GOOPS functional setter |
Date: |
Fri, 13 Jan 2017 22:33:05 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
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 <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.nl
Re: GOOPS functional setter,
Jan Nieuwenhuizen <=