From: "Thompson, David" <dthompson2@worcester.edu>
To: Guile User <guile-user@gnu.org>
Subject: MOP issues with <redefinable-class>
Date: Fri, 29 Jan 2021 08:29:08 -0500 [thread overview]
Message-ID: <CAJ=RwfbHnatAxdLcGELN78um_edEnDyukQ-TUEHb_ouAZb3J6Q@mail.gmail.com> (raw)
I've been playing around with GOOPS and the metaobject protocol
lately. It has been fun, but I've hit a snag with redefinable classes.
Here's a contrived example program that demonstrates my problem:
(use-modules (oop goops)
(srfi srfi-111))
(define-class <meta> (<class>))
(define (boxed-slot? slot)
(get-keyword #:box? (slot-definition-options slot)))
(define-method (compute-getter-method (class <meta>) slot)
(if (boxed-slot? slot)
(make <method>
#:specializers (list class)
#:procedure (let ((slot-name (slot-definition-name slot)))
(lambda (obj)
(unbox (slot-ref obj slot-name)))))
(next-method)))
(define-method (compute-setter-method (class <meta>) slot)
(if (boxed-slot? slot)
(make <method>
#:specializers (list class <top>)
#:procedure (let ((slot-name (slot-definition-name slot)))
(lambda (obj value)
(set-box! (slot-ref obj slot-name) value))))
(next-method)))
(define-class <foo> ()
(bar #:accessor bar #:box? #t #:init-form (box 123))
#:metaclass <meta>)
(define-class <redefinable-foo> ()
(bar #:accessor bar #:box? #t #:init-form (box 123))
#:metaclass <redefinable-class>)
;; This works:
(pk (+ (bar (make <foo>)) 456))
;; This throws an error:
(pk (+ (bar (make <redefinable-foo>)) 456))
The above code introduces a metaclass, <meta>, that supports a special
slot option: #:box? The metaclass arranges for boxed slots to be
boxed/unboxed transparently via the slot's accessor methods when it
detects the presence of #:box? #t in the slot options. However, the
redefinable class implementation does a transformation of the slot
definitions in its compute-slot method and discards all non-standard
slot options, so the final line throws an error because the bar method
returns a box, not a number.
I see two possibilities:
1) Slots are not designed to be extended with custom options, but it
just happens to work in the case of <class>
2) There's a bug in compute-slots for <redefinable-class>
Is this a bug or as-designed?
Thanks,
- Dave
next reply other threads:[~2021-01-29 13:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 13:29 Thompson, David [this message]
2021-01-29 16:07 ` MOP issues with <redefinable-class> Thompson, David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJ=RwfbHnatAxdLcGELN78um_edEnDyukQ-TUEHb_ouAZb3J6Q@mail.gmail.com' \
--to=dthompson2@worcester.edu \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).