guile-user
[Top][All Lists]
Advanced

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

Re: #:getter procedure returns unexpected value in GOOPS


From: Diogo F. S. Ramos
Subject: Re: #:getter procedure returns unexpected value in GOOPS
Date: Sat, 26 Apr 2014 14:35:05 -0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

> "Diogo F. S. Ramos" <address@hidden> 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 <foo> ()
>>   (a #:init-form 'foo #:getter foo-a)
>>   (b #:init-form 42))
>>
>> (define-class <bar> (<foo>)
>>   (a #:init-form 'bar))
>>
>>   (foo-a (make <foo>)) => foo
>>   (foo-a (make <bar>)) => 42
>>
>> I expected:
>>
>>   (foo-a (make <bar>)) => 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 <foo> ()
  (a #:init-value 'foo #:getter foo-a)
  (b #:init-value 42))

(define-class <bar> (<foo>)
  (a #:init-value 'bar))

(format #t "~a~%" (foo-a (make <foo>)))
(format #t "~a~%" (foo-a (make <bar>)))
--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 ‘define-class’ expression.



reply via email to

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