From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Noah Lavine Newsgroups: gmane.lisp.guile.user Subject: Re: Are `eqv?' and `eq?' the same? Date: Sun, 25 Aug 2013 08:41:24 -0400 Message-ID: References: <5219ED00.9040006@gmx.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b86f29658161204e4c4f668 X-Trace: ger.gmane.org 1377434514 30900 80.91.229.3 (25 Aug 2013 12:41:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 Aug 2013 12:41:54 +0000 (UTC) Cc: Guile Mailing List To: Alexandru Cojocaru Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Aug 25 14:41:58 2013 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VDZdl-0006IH-Ma for guile-user@m.gmane.org; Sun, 25 Aug 2013 14:41:57 +0200 Original-Received: from localhost ([::1]:46044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDZdl-0001Sq-Bt for guile-user@m.gmane.org; Sun, 25 Aug 2013 08:41:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDZdb-0001SY-IC for guile-user@gnu.org; Sun, 25 Aug 2013 08:41:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VDZda-0004mN-GY for guile-user@gnu.org; Sun, 25 Aug 2013 08:41:47 -0400 Original-Received: from mail-pa0-x233.google.com ([2607:f8b0:400e:c03::233]:55096) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDZda-0004mB-5j for guile-user@gnu.org; Sun, 25 Aug 2013 08:41:46 -0400 Original-Received: by mail-pa0-f51.google.com with SMTP id lf1so2387256pab.24 for ; Sun, 25 Aug 2013 05:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=uuYGoiaPy3kzUJNeE5vDOuOAOZlbyNcYwatKL8ac7o8=; b=F5MqsEEz3bKGJJF5w6c26HuMKbNtBbeTSUeZv9HXH4RmIoeOlvZCTgpWU+w5Hb7h3x so+xG1n6OQx3GmsQyLgnZ7082EfJMV8RkEuF2P03x3VNYWZSwLZos6c5GRf1iSApVLgL aRPqaugaxdl3I8fb7b7LevHZC52lo0InzIzLcl+tDT1L0xbhJLEd4JzS9ZXzxOsB8sB3 jSmp+cQw96V4yvQkiMRVx4XUQuevRAdYNI+X8Cg5O72L2qhl2kEv8lWxCyrZ0oL91IR7 M8jgh2G0XIY9aDdzXeuqOI+OtZgA8+VHenffc7dJGSoYXAziVhSlLVFQW8zjKiTRo0g5 YGDw== X-Received: by 10.68.93.227 with SMTP id cx3mr1075763pbb.146.1377434504531; Sun, 25 Aug 2013 05:41:44 -0700 (PDT) Original-Received: by 10.68.91.1 with HTTP; Sun, 25 Aug 2013 05:41:24 -0700 (PDT) In-Reply-To: <5219ED00.9040006@gmx.com> X-Google-Sender-Auth: 5xYrW6e6Hq_LAggHLl7tAlpW7Fo X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::233 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:10690 Archived-At: --047d7b86f29658161204e4c4f668 Content-Type: text/plain; charset=ISO-8859-1 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 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 > --047d7b86f29658161204e4c4f668 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hello,

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

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

The particular case you mention is not a bug, but it's a= lso 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 mean= s that the obvious eq? implementation treats them as the same thing. This i= s allowed by the standard, but it won't hold true for big numbers, whic= h are represented as blocks of memory allocated in the heap.

Best,
Noah

=
On Sun, Aug 25, 2013 at 7:39 AM, Alexandru C= ojocaru <xojoc@gmx.com> wrote:
=20 =20 =20
Hi,

from the GUILE manual [0]:


=A0=A0=A0 `eq?
' tests just for the same object (essentia= lly a pointer comparison)
=A0=A0=A0 `eqv?'
extends `eq?' to look at= the value of numbers and characters.

this is what I get:

=A0=A0=A0 scheme@(guile-user)> (eq? 3 (+ 1 2))
=A0=A0=A0 $1 =3D #t

is this behavior intentional or some type of bug?

Best regards,
Alexandru Cojocaru

[0]: https://www.gnu.org/software/guile/manual/html_nod= e/Equality.html

--047d7b86f29658161204e4c4f668--