[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: goops and equal?
From: |
Jan Nieuwenhuizen |
Subject: |
Re: goops and equal? |
Date: |
Wed, 12 Nov 2014 14:55:29 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Mark H Weaver writes:
> 'equal?' is actually a "primitive generic", which means that it's a core
> C function that handles the cases it knows about, and only calls out to
> user-defined GOOPS methods for cases that aren't handled internally.
>
> One of the facts known by core 'equal?' is that objects of different
> types are not equal.
That makes sense; once you know it.
> It may be that we should relax this somewhat, but IMO it's probably a
> bad idea to allow instances of your user-defined type to be 'equal?' to
> symbols. Out of curiosity, why do you want this?
Mainly because of surprise/symmetry. The manual says equal? becomes
a generic once Goops is loaded.
I agree that it's unwise or at least bad taste to implement equal?
for different objects to be the same.
I have a situation where the compared objects could be the same,
or one could be a symbol which has the same semantics.
(define-class <type> ()
(name :accessor .name :init-value 'void :init-keyword :name))
(define-method (type-equal? (a <type>) (b <symbol>))
(eq? (.name a) b))
Now I must provide a type-equal? wrapper for the equal? method
I already have, ie
(define-method (type-equal? (a <type>) (b <type>))
(equal? a b))
that I could omit if the first type-symbol one could be called equal?
Thanks!
Greetings, Jan
--
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.nl