[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
goops and equal?
From: |
Jan Nieuwenhuizen |
Subject: |
goops and equal? |
Date: |
Mon, 10 Nov 2014 13:57:56 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Hi,
In the example below, my implementation of equal? is only being
used if both types are the same. That surprised me; the manual
says equal? becomes a generic and for normal generics this works
as I expect.
How do I get the magic equal? to do what show the same result as the
simple generic type-equal?
And also, do we want such surprises?
Greetings,
Jan
(read-set! keywords 'prefix)
(use-modules (oop goops))
(define-class <type> ()
(name :accessor .name :init-value #f :init-keyword :name))
(define-method (equal? (a <type>) (b <type>))
(display "<type>equal?\n")
(eq? (.name a) (.name b)))
(define-method (equal? (a <type>) (b <symbol>))
(display "<type0>equal?\n")
(eq? (.name a) b))
(define-method (type-equal? (a <type>) (b <symbol>))
(display "<type1>equal?\n")
(eq? (.name a) b))
(format #t "equal?: ~a\n" (equal? (make <type> :name 'a) (make <type> :name
'a)))
(newline)
(format #t "equal?: ~a\n" (equal? (make <type> :name 'a) 'a))
(newline)
(format #t "type-equal?: ~a\n" (type-equal? (make <type> :name 'a) 'a))
(newline)
--
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.nl
- goops and equal?,
Jan Nieuwenhuizen <=