unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Jan Nieuwenhuizen <janneke@gnu.org>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-user@gnu.org
Subject: Re: goops and equal?
Date: Wed, 12 Nov 2014 14:55:29 +0100	[thread overview]
Message-ID: <87h9y44j72.fsf@drakenvlieg.flower> (raw)
In-Reply-To: <87sihpiuec.fsf@yeeloong.lan> (Mark H. Weaver's message of "Tue,  11 Nov 2014 11:17:31 -0500")

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



  reply	other threads:[~2014-11-12 13:55 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
2014-11-11 16:17 ` Mark H Weaver
2014-11-12 13:55   ` Jan Nieuwenhuizen [this message]
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=87h9y44j72.fsf@drakenvlieg.flower \
    --to=janneke@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=mhw@netris.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).