From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: John Cowan Newsgroups: gmane.lisp.guile.user Subject: Re: Surprising behavior of eq? Date: Sun, 20 Sep 2020 13:05:12 -0400 Message-ID: References: <8e1d9874-4659-cca5-03da-c2c0df102c56@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="901"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 20 19:05:51 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kK2md-00008v-Gk for guile-user@m.gmane-mx.org; Sun, 20 Sep 2020 19:05:51 +0200 Original-Received: from localhost ([::1]:38738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kK2mc-0001ET-I0 for guile-user@m.gmane-mx.org; Sun, 20 Sep 2020 13:05:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kK2mI-0001Dy-Ml for guile-user@gnu.org; Sun, 20 Sep 2020 13:05:32 -0400 Original-Received: from mail-qt1-x835.google.com ([2607:f8b0:4864:20::835]:45519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kK2mC-0004qJ-Q2 for guile-user@gnu.org; Sun, 20 Sep 2020 13:05:30 -0400 Original-Received: by mail-qt1-x835.google.com with SMTP id z2so10208039qtv.12 for ; Sun, 20 Sep 2020 10:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ccil-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1kU8Ba2x6/BhReaYdBBj2p5UrXoDTQQFn5kByCVJNk8=; b=HNfd9sCEZZJNgSV31m5jEDkMl29Wlr2jc8w5K9KP2OvmgJzG62pi4fcU76RnogqOc6 whOynGhZ+YEtW5dB2OM52X6KtRnMF/tib2SYGaz5GmP3vgHxyhGY+7qcdLdkdExYP5ay XjHWaDsKb4kQdxqZFwTj9CYFDp6UyXd6VicW+y43DHZRMthkzyrPTeIZJrDL/LpxwSzv SNjEQ3iemn5y25BWktUUx5y9+fJlU6BoxbUplqAp/5HLh0vf4yXHTJ8odpUkCzWoy2VV heeCVyQnoaE9lhNgE0v/aMmav8OCljg9d6aqeViI46sUjKyQR+5u3est5vtV+8+ib58W y60Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1kU8Ba2x6/BhReaYdBBj2p5UrXoDTQQFn5kByCVJNk8=; b=lmCGKZHhp2ckuC+LRRPms500pMG0U6coNyUg2thq5rlem3YW9nhId/h14OpIIwiJrg fi+XW98lBO5hfY4pw7vx7WKDVNoPqRMgx1Zo6m1D8g7qkl2WX+h30AUkIAE9BZOTaCfe zzLKu/KzcN76HJHXlG1MwrMzSNYPpWcZYWSPYXJDcQdT3M8CUTda57+D90n/xljq31HQ /7yRCOrYSveyTaTlCNXP2ZxsQJ1HvlbXY2LRb0Mh44o6NUJhSzgangSqc1HbrFFEK1hh XD54AARSe1rQYiwoyOlu8ELiQQ0grJw6lcgmohKkO6MM++EPcjoH+0TERa9GNJjIC62p ye+A== X-Gm-Message-State: AOAM53348jNYfZNZZbdnJNH6ouiWthfhT2PepjiR0Zh2rEK6GIWB9FLm Yyi2hs7DgBMEtx/Iz05cmdDzZyaqNn1QfdP8NNOAaQ== X-Google-Smtp-Source: ABdhPJy/JdKcePvFql8u0+spBh+PhFe34kJmspr5eNUrEYcD9nG3A6zf3Ff+uy4eCIDmZH4zITQEfLf0gxEDYCel6g8= X-Received: by 2002:ac8:fec:: with SMTP id f41mr38939656qtk.186.1600621523624; Sun, 20 Sep 2020 10:05:23 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::835; envelope-from=cowan@ccil.org; helo=mail-qt1-x835.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16939 Archived-At: On Sun, Sep 20, 2020 at 11:37 AM Zelphir Kaltstahl < zelphirkaltstahl@posteo.de> wrote: > "This is where the eqv? predicate comes into picture. The eqv? is exactly > the same as the eq? predicate, except that it will always return #t for > same primitive values." > > Of course SO is not a standard. Either it is simply wrong, or I > misunderstood "primitive values" in that phrase. I thought: "Ah strings are > a primitive value, so eqv? should work in all cases when comparing > strings." However, this has been debunked. > Strings tend to be treated as primitive values, but technically they are compound values, just as much as vectors are. And like vectors, you can change the characters of a string without changing its identity. > The only thing I do not quite understand yet is: What is the difference > between (eqv? ...) and (eq? ...) then? > Efficiency only. > If (eqv? ...) is only #t if things get consolidated in the same store > place, would that not be the same as pointer equivalence? > Eq? is allowed to return #f on identical-looking characters and numbers because they may or may not involve allocation. Characters and fixnums (integers up to about 2^60) are generally not allocated and eq? will return #t on them, but larger integers and other types almost certainly will not: (let ((i (* 48923498234892340 78902372789023)) (j (* 48923498234892340 78902372789023))) (eq? i j)) => #f That's because the values of both i and j have to be allocated, and therefore aren't represented by the same pointers. But unlike strings, you can't mutate the digits of an integer, so providing eqv? gives us an abstract notion of identity. The Scheme standards simplify the situation by saying that eq? may return #f even when eqv? returns #t in the cases of numbers and characters. Because of these strange effects, I recommend (and this is just me) not using eq? unless you can prove that you need the additional effi. Note that (eq? 5 5.0) and (eqv? 5 5.0) are both #f, so if you want to compare for numeric equality you should use (= 5 5.0) => #t. The reason they are not identical is that they behave differently: (/ 5.0 2) => 2.5, whereas (/ 5 2) => 5/2. Here's an example that shows us that Guile does not consolidate number literals, although it could: (eqv? 3860180095872584138419938783820 3860180095872584138419938783820) =>#f (In R7RS, procedures that are eqv? aren't necessarily eq? either, and in R6RS even procedures that seem totally identical may be neither eq? nor eqv?. That's another story.)