From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jan Nieuwenhuizen Newsgroups: gmane.lisp.guile.user Subject: Re: GOOPS functional setter Date: Fri, 13 Jan 2017 22:33:05 +0100 Organization: AvatarAcademy.nl Message-ID: <87bmva7ii6.fsf@gnu.org> References: <871sw6g4je.fsf@dustycloud.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1484343241 17869 195.159.176.226 (13 Jan 2017 21:34:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 13 Jan 2017 21:34:01 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: Guile user To: Christopher Allan Webber Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jan 13 22:33:53 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cS9Th-0002yZ-Gx for guile-user@m.gmane.org; Fri, 13 Jan 2017 22:33:41 +0100 Original-Received: from localhost ([::1]:45381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cS9Tm-00062O-95 for guile-user@m.gmane.org; Fri, 13 Jan 2017 16:33:46 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cS9TP-00061n-EE for guile-user@gnu.org; Fri, 13 Jan 2017 16:33:24 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cS9TM-0003uk-Bn for guile-user@gnu.org; Fri, 13 Jan 2017 16:33:23 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cS9TA-0003kv-3S; Fri, 13 Jan 2017 16:33:08 -0500 Original-Received: from peder.onsbrabantnet.nl ([88.159.206.46]:41552 helo=dundal.peder.onsbrabantnet.nl) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cS9T9-0003I7-Gj; Fri, 13 Jan 2017 16:33:07 -0500 X-Url: http://AvatarAcademy.nl In-Reply-To: <871sw6g4je.fsf@dustycloud.org> (Christopher Allan Webber's message of "Fri, 13 Jan 2017 13:09:57 -0600") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13097 Archived-At: 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)))=20 (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))) in= itializers)) (initializers (append (apply append initializers) setters)) (arguments (cons class initializers))) (apply make arguments))) --8<---------------cut here---------------end--------------->8--- Usage: (clone o #:slot ...) =20=20=20 Greetings, Jan --=20 Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar=C2=AE http://AvatarAcademy.nl= =20=20