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: Setting Immutible Classes? Date: Fri, 06 Oct 2017 10:46:53 -0500 Message-ID: <87tvzcb7o2.fsf@dustycloud.org> References: <1507269654.28034.8.camel@qlfiles.net> <87wp48ztc7.fsf@netris.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1507304851 28014 195.159.176.226 (6 Oct 2017 15:47:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 6 Oct 2017 15:47:31 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 25.3.1 Cc: Guile User Mailing List To: Mark H Weaver Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Oct 06 17:47:23 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 1e0UqQ-0006J2-EM for guile-user@m.gmane.org; Fri, 06 Oct 2017 17:47:22 +0200 Original-Received: from localhost ([::1]:45572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0UqX-0006qK-WA for guile-user@m.gmane.org; Fri, 06 Oct 2017 11:47:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0Uq7-0006q6-Bh for guile-user@gnu.org; Fri, 06 Oct 2017 11:47:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0Uq4-0003Os-9w for guile-user@gnu.org; Fri, 06 Oct 2017 11:47:03 -0400 Original-Received: from dustycloud.org ([50.116.34.160]:32792) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e0Uq4-0003Nc-5B for guile-user@gnu.org; Fri, 06 Oct 2017 11:47:00 -0400 Original-Received: from oolong (localhost [127.0.0.1]) by dustycloud.org (Postfix) with ESMTPS id 29948265D0; Fri, 6 Oct 2017 11:46:55 -0400 (EDT) In-reply-to: <87wp48ztc7.fsf@netris.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 50.116.34.160 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:14193 Archived-At: Mark H Weaver writes: > Christopher Howard writes: > >> Hi, is the a way I could use goops such that I the classes are non- >> mutating, but have setters that simply return a new instance of the >> class (instead of modifying the original)? > > We provide such a mechanism for SRFI-9 Records. Search for "Functional > Setters" in section 6.6.16 (SRFI-9 Records) of the Guile manual. > >> I suppose I could simply use define-method to create setter methods >> which create a new instance of the object; but that would get rather >> complicated, wouldn't it, if the object had superclasses? So I need >> some kind of shallow copy mechanism for the whole object, or a chained >> copy mechanism...? > > For GOOPS classes, take a look at the built-in 'shallow-clone' generic > function. It is described in section 8.10 (GOOPS Object Miscellany). > > Mark See also https://lists.gnu.org/archive/html/guile-user/2017-01/msg00030.html which includes both a slot-fset approach and a clone macro. Personally I've come to like the clone macro more over time.