From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: Dave Thompson <dthompson2@worcester.edu>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: Add support for record types in GOOPS methods?
Date: Tue, 21 Oct 2014 17:37:53 +0200 [thread overview]
Message-ID: <CAMFYt2ZTEtkddHnBNFKWoTYZzsTkkCH1ePWE4vX2yerDAamr_g@mail.gmail.com> (raw)
In-Reply-To: <8d1tq1fp1q.fsf@freestation00.office.fsf.org>
[-- Attachment #1: Type: text/plain, Size: 1864 bytes --]
2014-10-21 16:57 GMT+02:00 Dave Thompson <dthompson2@worcester.edu>:
> Hello all,
>
> Last night, I encountered what I consider to be a frustrating limitation
> of GOOPS methods: They do not support record type descriptors, only
> classes. This makes it difficult to take advantage of generic
> procedures without also buying into the rest of the GOOPS system.
>
> Here's some code that I wish would work:
>
> (define-record-type <foo>
> (make-foo bar)
> foo?
> (bar foo-bar))
>
> (define-method (foobar (foo <foo>))
> (foo-bar foo))
>
> The error thrown by `define-method' is:
>
> ERROR: In procedure class-direct-methods:
> ERROR: In procedure slot-ref: Wrong type argument in position 1
> (expecting instance): #<record-type <foo>>
>
> There is an ugly workaround. You can use `class-of' on an instance of a
> record type to get a class in return.
>
> This code works, but is unideal:
>
> (define-record-type <foo>
> (make-foo bar)
> foo?
> (bar foo-bar))
>
> (define <foo-class> (class-of (make-foo #f)))
>
> (define-method (foobar (foo <foo-class>))
> (foo-bar foo))
>
> I don't know very much about GOOPS, so I am seeking help. Would it make
> sense for `define-method' to work the way I want? If so, could anyone
> suggest a way to make `define-method' to DTRT for record types? Perhaps
> it could auto-generate and cache the class from the record type
> descriptor, but I'm not sure how since the current workaround requires
> an instance of that record.
>
>
Hi!
As I managed to find out, the (define-record-type t ...) also introduces a
GOOPS class named <t>. Following your example, you'd need to define your
method in the following way:
(define-method (foobar (foo <<foo>>))
(foo-bar foo))
I don't think any further changes are needed (perhaps a section in the
documentation would be nice)
HTH
[-- Attachment #2: Type: text/html, Size: 3256 bytes --]
next prev parent reply other threads:[~2014-10-21 15:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-21 14:57 Add support for record types in GOOPS methods? Dave Thompson
2014-10-21 15:37 ` Panicz Maciej Godek [this message]
2014-10-21 16:00 ` 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=CAMFYt2ZTEtkddHnBNFKWoTYZzsTkkCH1ePWE4vX2yerDAamr_g@mail.gmail.com \
--to=godek.maciek@gmail.com \
--cc=dthompson2@worcester.edu \
--cc=guile-devel@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).