From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Diogo F. S. Ramos" Newsgroups: gmane.lisp.guile.user Subject: Re: #:getter procedure returns unexpected value in GOOPS Date: Sat, 26 Apr 2014 14:35:05 -0300 Message-ID: <87a9b8hu46.fsf@nebulosa.milkyway> References: <87mwf9hu1v.fsf@nebulosa.milkyway> <877g6ccm4w.fsf@ossau.homelinux.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1398534200 2795 80.91.229.3 (26 Apr 2014 17:43:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 26 Apr 2014 17:43:20 +0000 (UTC) Cc: guile-user@gnu.org To: Neil Jerram Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Apr 26 19:43:13 2014 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1We6d5-0001Th-Nw for guile-user@m.gmane.org; Sat, 26 Apr 2014 19:43:11 +0200 Original-Received: from localhost ([::1]:35935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1We6d4-0005ZK-QT for guile-user@m.gmane.org; Sat, 26 Apr 2014 13:43:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1We6Wa-0007zs-7O for guile-user@gnu.org; Sat, 26 Apr 2014 13:37:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1We6VV-0006PY-Bn for guile-user@gnu.org; Sat, 26 Apr 2014 13:36:27 -0400 Original-Received: from mx1.riseup.net ([198.252.153.129]:37804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1We6VV-0006Or-63 for guile-user@gnu.org; Sat, 26 Apr 2014 13:35:21 -0400 Original-Received: from fruiteater.riseup.net (fruiteater-pn.riseup.net [10.0.1.74]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Gandi Standard SSL CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 5ED4458B2C; Sat, 26 Apr 2014 10:35:20 -0700 (PDT) Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dfsr@fruiteater.riseup.net) with ESMTPSA id 65114E8C In-Reply-To: <877g6ccm4w.fsf@ossau.homelinux.net> (Neil Jerram's message of "Sat, 26 Apr 2014 13:26:23 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Virus-Scanned: clamav-milter 0.98.1 at mx1 X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 198.252.153.129 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 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-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:11220 Archived-At: > "Diogo F. S. Ramos" writes: > >> When using GOOPS, if a class has a second slot, the #:getter procedure >> of the first slot returns the value of the second slot when applied to >> an instance of a subclass. >> >> (use-modules (oop goops)) >> >> (define-class () >> (a #:init-form 'foo #:getter foo-a) >> (b #:init-form 42)) >> >> (define-class () >> (a #:init-form 'bar)) >> >> (foo-a (make )) =3D> foo >> (foo-a (make )) =3D> 42 >> >> I expected: >> >> (foo-a (make )) =3D> bar >> >> I'm not too familiar with GOOPS, so I'm not sure this is the right >> behavior. > > Do you see this if you use #:init-value instead of #:init-form ? It > sounds to me like #:init-value is what you really want, and I suspect > you're seeing undefined behaviour that arises from giving an > unparenthesized form ('42') to #:init-form. I tried changing all to `#:init-value', but the result was the same. --8<---------------cut here---------------start------------->8--- (use-modules (oop goops)) (define-class () (a #:init-value 'foo #:getter foo-a) (b #:init-value 42)) (define-class () (a #:init-value 'bar)) (format #t "~a~%" (foo-a (make ))) (format #t "~a~%" (foo-a (make ))) --8<---------------cut here---------------end--------------->8--- Also, according to the documentation, it would not be what I want. INIT-VALUE specifies a fixed initial slot value (shared across all new instances of the class). I want a slot value that is exclusive to an instance. INIT-FORM specifies a form that, when evaluated, will return an initial value for the slot. The form is evaluated each time that an instance of the class is created, in the lexical environment of the containing =E2=80=98define-class=E2=80=99 expression.