[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GOOPS functional setter

From: Christopher Allan Webber
Subject: Re: GOOPS functional setter
Date: Fri, 13 Jan 2017 20:11:28 -0600
User-agent: mu4e 0.9.18; emacs 25.1.1

address@hidden writes:

> 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.)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]