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: Ludovic Courtès
Subject: Re: Goops generic-functions and srfi-64 tests
Date: Sun, 23 Nov 2014 18:20:03 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Dmitry Bogatov <address@hidden> skribis:

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

This really shouldn’t be needed, and I would even expect it to lead to
infinite recursion actually.

> (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.

Hmm, simply doing the following works for me:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(oop goops)
scheme@(guile-user)> (define-method (equal? (a <object>) (b <object>)) 42)
scheme@(guile-user)> (equal? 1 2)
$1 = #f
scheme@(guile-user)> (equal? <class> <string>)
$2 = 42
--8<---------------cut here---------------end--------------->8---

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

What do you mean by “simple module”?

Thanks,
Ludo’.



reply via email to

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