unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Noah Lavine <noah.b.lavine@gmail.com>
To: Alexandru Cojocaru <xojoc@gmx.com>
Cc: Guile Mailing List <guile-user@gnu.org>
Subject: Re: Are `eqv?' and `eq?' the same?
Date: Sun, 25 Aug 2013 08:41:24 -0400	[thread overview]
Message-ID: <CA+U71=NLWmWc-WeNZ1UE141eA0NdZJnUvo2XKiYToQVwexz-aQ@mail.gmail.com> (raw)
In-Reply-To: <5219ED00.9040006@gmx.com>

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

Hello,

eq? and eqv? are sort of a funny pair. eqv? actually has sensible semantics
- if two things are eqv?, then a normal scheme program should never notice
the difference between them (they are operationally equivalent). eq? is
defined not in terms of Scheme, but in terms of Scheme's implementation -
two things are eq? if they are represented with the same bit of memory.

The reason for eq? is that eq? can be implemented very efficiently,
especially on old hardware that was current when that part of the Scheme
standard was written. For some types (i.e. booleans and symbols), eq? is
the same as eqv?, so eq? is used like a higher-performing shortcut to eqv?.
Nowadays, it's probably best to just use eqv? and spend your time worrying
about cache misses if you care about performance.

The particular case you mention is not a bug, but it's also not guaranteed
to work for all numbers. Guile represents small numbers (less than 2^62 on
64-bit systems, I believe) without a pointer, which means that the obvious
eq? implementation treats them as the same thing. This is allowed by the
standard, but it won't hold true for big numbers, which are represented as
blocks of memory allocated in the heap.

Best,
Noah


On Sun, Aug 25, 2013 at 7:39 AM, Alexandru Cojocaru <xojoc@gmx.com> wrote:

>  Hi,
>
> from the GUILE manual [0]:
>
>     `eq?' tests just for the same object (essentially a pointer
> comparison)
>     `eqv?' extends `eq?' to look at the value of numbers and characters.
>
> this is what I get:
>
>     scheme@(guile-user)> (eq? 3 (+ 1 2))
>     $1 = #t
>
> is this behavior intentional or some type of bug?
>
> Best regards,
> Alexandru Cojocaru
>
> [0]: https://www.gnu.org/software/guile/manual/html_node/Equality.html
>

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

  parent reply	other threads:[~2013-08-25 12:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-25 11:39 Are `eqv?' and `eq?' the same? Alexandru Cojocaru
2013-08-25 12:39 ` Pascal J. Bourguignon
2013-08-25 12:41 ` Noah Lavine [this message]
2013-08-25 20:13 ` Ian Price

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='CA+U71=NLWmWc-WeNZ1UE141eA0NdZJnUvo2XKiYToQVwexz-aQ@mail.gmail.com' \
    --to=noah.b.lavine@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=xojoc@gmx.com \
    /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).