2014-10-21 16:57 GMT+02:00 Dave Thompson <dthomps...@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

Reply via email to