guile-user
[Top][All Lists]
Advanced

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

Re: Goops generic-functions and srfi-64 tests


From: Dmitry Bogatov
Subject: Re: Goops generic-functions and srfi-64 tests
Date: Sun, 23 Nov 2014 10:27:59 +0300
User-agent: Mutt/1.5.22.1 (2013-10-16)

> > Recently I noticed, that srfi-64 `assert-equal` macro do not use
> > `equal?` that was redefinded via `define-method` in scope of invocation
> > of `assert-equal`.
> No, that’s normally not a problem: (define-method (equal? ...) ...)
> should turn the core ‘equal?’ primitive into a generic function, and
> things would work well because (@@ (srfi srfi-64) equal?) is the same
> as (@ (guile) equal?).

> How exactly did you define ‘equal?’ methods?
I define class object as

    (module-define! (current-module) '<struct-foo>
        (make <class> #:dsupers (list <object>) #:slots ...))

and after just

(define-method (equal? x y)
  ((@ (guile) equal?) x y))

(define-method (equal? (this <object>) (other <object>))
  (let* ((class_ (class-of this))
         (slots (map car (class-slots class_))))
    (define (slot-values instance)
      (map (cute slot-ref instance <>) slots))
    (if (eq? class_ (class-of other))
        (false-if-exception (equal? (slot-values this) (slot-values other)))
      #f)))

I do not know, why first one `equal?` is needed, but otherwise guile
complained, that no method is present to compare two lists.

Interesting enough, I created simple module, and behaves as it should.
Maybe you have some wild guess about class being defined not via macro?

--
Best regards, Dmitry Bogatov <address@hidden>,
Free Software supporter, esperantisto and netiquette guardian.
GPG: 54B7F00D

Attachment: pgpAjJCfEwwVT.pgp
Description: PGP signature


reply via email to

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