unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Nala Ginrut <nalaginrut@gmail.com>
To: Jan Nieuwenhuizen <janneke@gnu.org>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: goops and equal?
Date: Mon, 10 Nov 2014 21:03:14 +0800	[thread overview]
Message-ID: <CAPjoZodR7w2DXRN2FSq-jgt7HwLWT+ZuLxZBQ-a78z=VDv1QbA@mail.gmail.com> (raw)
In-Reply-To: <87wq73ciwb.fsf@drakenvlieg.flower>

[-- Attachment #1: Type: text/plain, Size: 1506 bytes --]

I think you have to define your specific certain-class-equal?
So does record-type.
 2014年11月10日 下午8:58于 "Jan Nieuwenhuizen" <janneke@gnu.org>写道:

> 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 <janneke@gnu.org> | GNU LilyPond http://lilypond.org
> Freelance IT http://JoyofSource.com | Avatar®  http://AvatarAcademy.nl
>
>

[-- Attachment #2: Type: text/html, Size: 2231 bytes --]

  reply	other threads:[~2014-11-10 13:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-10 12:57 goops and equal? Jan Nieuwenhuizen
2014-11-10 13:03 ` Nala Ginrut [this message]
2014-11-11 16:17 ` Mark H Weaver
2014-11-12 13:55   ` Jan Nieuwenhuizen
2014-11-13 16:56     ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPjoZodR7w2DXRN2FSq-jgt7HwLWT+ZuLxZBQ-a78z=VDv1QbA@mail.gmail.com' \
    --to=nalaginrut@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=janneke@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).