guile-devel
[Top][All Lists]
Advanced

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

Add support for record types in GOOPS methods?


From: Dave Thompson
Subject: Add support for record types in GOOPS methods?
Date: Tue, 21 Oct 2014 10:57:53 -0400
User-agent: Notmuch/0.17 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu)

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.

Thanks!

-- 
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate



reply via email to

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