From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Christopher Allan Webber Newsgroups: gmane.lisp.guile.user Subject: Re: GOOPS functional setter Date: Fri, 13 Jan 2017 20:11:28 -0600 Message-ID: <87vatie6gf.fsf@dustycloud.org> References: <871sw6g4je.fsf@dustycloud.org> <20170113205646.GB10416@tuxteam.de> 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 1484359919 21099 195.159.176.226 (14 Jan 2017 02:11:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 14 Jan 2017 02:11:59 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 25.1.1 Cc: guile-user@gnu.org To: tomas@tuxteam.de Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jan 14 03:11:55 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 1cSDos-0004ew-0e for guile-user@m.gmane.org; Sat, 14 Jan 2017 03:11:50 +0100 Original-Received: from localhost ([::1]:46096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSDow-0007sv-B0 for guile-user@m.gmane.org; Fri, 13 Jan 2017 21:11:54 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSDoZ-0007r0-Rz for guile-user@gnu.org; Fri, 13 Jan 2017 21:11:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cSDoY-0007mQ-S3 for guile-user@gnu.org; Fri, 13 Jan 2017 21:11:31 -0500 Original-Received: from dustycloud.org ([2600:3c02::f03c:91ff:feae:cb51]:50704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cSDoY-0007jV-Nm for guile-user@gnu.org; Fri, 13 Jan 2017 21:11:30 -0500 Original-Received: from oolong (localhost [127.0.0.1]) by dustycloud.org (Postfix) with ESMTPS id 96F4826625; Fri, 13 Jan 2017 21:11:28 -0500 (EST) In-reply-to: <20170113205646.GB10416@tuxteam.de> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2600:3c02::f03c:91ff:feae:cb51 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:13098 Archived-At: tomas@tuxteam.de writes: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Fri, Jan 13, 2017 at 01:09:57PM -0600, Christopher Allan Webber wrot= e: >> I guess I never sent this to this list. Here's a functional setter fo= r >> GOOPS classes. >> >> Maybe nobody else would use it, but I've used it in a couple of projec= ts >> now, so figure I might as well share. >> >> This is LGPLv3+. Feel free to use. >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D >> >> ;; By Christopher Allan Webber, LGPLv3+; adapted from shallow-clone in= GOOPS >> (use-modules (oop goops)) >> >> (define-method (slot-fset (self ) slot-name value) >> "Return a new copy of SELF, with all slots preserved except SLOT-NAM= E >> set to VALUE." > > (from the peanut gallery) > > I understand now what it does, but the name "slot-fset" would confuse t= he heck > of me. Why not something like "clone" or perhaps "clone*"? > > regards > - -- tom=C3=A1s 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.)