From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Schmiedl Newsgroups: gmane.lisp.guile.user Subject: Re: Surprising behavior of eq? Date: Sun, 20 Sep 2020 15:57:43 +0200 Organization: EDV-Beratung Schmiedl Message-ID: <687423933.20200920155743@xss.de> References: <8e1d9874-4659-cca5-03da-c2c0df102c56@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15285"; mail-complaints-to="usenet@ciao.gmane.io" To: Zelphir Kaltstahl , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 20 16:17:19 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 1kK09X-0003q5-8Z for guile-user@m.gmane-mx.org; Sun, 20 Sep 2020 16:17:19 +0200 Original-Received: from localhost ([::1]:36026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kK09W-0002wj-9r for guile-user@m.gmane-mx.org; Sun, 20 Sep 2020 10:17:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kK09H-0002wc-0a for guile-user@gnu.org; Sun, 20 Sep 2020 10:17:03 -0400 Original-Received: from s1.swsch.de ([2a01:4f8:a0:8074::2]:59604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kK09D-0000LX-IH for guile-user@gnu.org; Sun, 20 Sep 2020 10:17:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xss.de; s=s1; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:To: Message-ID:From:Date:Sender:Reply-To:Cc; bh=HUr/k8w4m1gxGsjE9vuH+bqBenOL72Z5j9KUl2Ihp70=; b=WPRAhW4XgjOt+HU0k1bYG6PwxE TZWeh2PkN27aFyl75yneJGfrDhX4DAeHwy5I6MpVYyGn6shBvD+gKHQkSVOK8OzgqTzB/CX+cOTLl 8bvLrmCcxg1YuAdFtpAIZ+tl6+tKAgULpChEzBVYXYFVErFCwg/I34/NCYT8n/SexCSE=; Original-Received: from [2003:d4:4741:7500:6942:6df:b785:9ba0] (helo=PC-DEV.fritz.box) by s1.swsch.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kJzqb-0006n2-9s; Sun, 20 Sep 2020 15:57:45 +0200 In-Reply-To: X-Scan-Signature: 00ce1eb22a2b33e121bbdeecf24f6e71 Received-SPF: pass client-ip=2a01:4f8:a0:8074::2; envelope-from=s@xss.de; helo=s1.swsch.de X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:16935 Archived-At: Let's have a little shop talk with guile: $ guile-3.0 GNU Guile 3.0.4-dirty scheme@(guile-user)> (eqv? "a" "a") $1 =3D #t Hypothesis: guile's reader recognizes that the contents of both string literals are the same and feeds the same string to the calling function.=20 Check: If that were the case, the two strings should not only be eqv? but also eq? scheme@(guile-user)> (eq? "a" "a") $2 =3D #t To see a different behaviour we need to avoid these literals and replace them by values not built while reading but while executing the code: scheme@(guile-user)> (equal? (list->string (list #\a)) (list->string (list = #\a))) $3 =3D #t Now we compare two different string values which happen to end up with identical content. And, behold: They are neither eqv? nor eq?. scheme@(guile-user)> (eqv? (list->string (list #\a)) (list->string (list #\= a))) $4 =3D #f scheme@(guile-user)> (eq? (list->string (list #\a)) (list->string (list #\a= ))) $5 =3D #f Now let's see if that is consistent with the standard: According to r5rs, section 6.1 "Equivalence predicates": The eqv? procedure returns #t if: ... * obj1 and obj2 are pairs, vectors, or strings that denote the same locations in the store (section 3.4). So we have learned=20 * that guile's reader reuses "store locations" for strings of identical content=20 * that eqv? is not the right predicate for content based string comparison HTH s. "Zelphir Kaltstahl" , 20.09.2020, 15:09: >=C2=A0And I've noticed something more about equality stuff in the context = of > tests: > ~~~~ > (eqv? "a" "a") > $3 =3D #t > ;; but (define char->>string > =C2=A0 (=CE=BB (c) > =C2=A0 =C2=A0 (list->string > =C2=A0 =C2=A0 =C2=A0(list c)))) > (import > =C2=A0 ;; unit tests > =C2=A0 (srfi srfi-64)) > (test-begin "string-utils-test") > (test-group > =C2=A0"char-to-string-test" > =C2=A0(test-eqv "char->string converts a character to a string" > =C2=A0 =C2=A0"a" > =C2=A0 =C2=A0(char->string #\a))) > (test-end "string-utils-test") > %%%% Starting test string-utils-test =C2=A0(Writing full log to "string-u= tils-test.log") > $2 =3D ("string-utils-test") :19: FAIL char->>string converts a character to a string > # of unexpected failures =C2=A01 > ~~~~ > So while (eqv? ...) gives the correct (?) result, the test procedure > (test-eqv ...) which seems to indicate using (eqv? ...) via its name > does not think of the two strings as equivalent. > On 20.09.20 14:19, Zelphir Kaltstahl wrote: >> Sorry, I misclicked "send" when I wanted to further edit my e-mail ... >> >> My Guile version is: >> >> ~~~~ >> (version) >> $6 =3D "3.0.4" >> ~~~~ >> >> On 20.09.20 14:16, Zelphir Kaltstahl wrote: >>> Hello Guile users, >>> >>> I just noticed something weird about eq?. >>> >>> My Guile version is: >>> >>> >>> I get the different results, depending on whether I define some >>> bindings in a let or using define: >>> >>> (In Emacs Geiser:) >>> >>> ~~~~ >>> (define x '(10 9)) >>> (define y '(10 9)) >>> (eq? x y) >>> $2 =3D #f >>> >>> (let ([x '(10 9)] >>> =C2=A0 =C2=A0 =C2=A0 [y '(10 9)]) >>> =C2=A0 =C2=A0 =C2=A0(eq? x y)) >>> $3 =3D #t >>> ~~~~ >>> >>> Is this intentional or a bug? >>> >>> I first noticed something strange when writing the following code: >>> >>> ~~~~DEFINITION~~~~ >>> (define make-multiple-list-remover >>> =C2=A0 (=CE=BB (equal-proc) >>> =C2=A0 =C2=A0 (=CE=BB (lst unwanted) >>> =C2=A0 =C2=A0 =C2=A0 (let loop ([remaining-list lst]) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cond >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[(null? remaining-list) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '()] >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[(equal-proc (car remaining-list) unw= anted) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop (cdr remaining-list))] >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[else >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cons (car remaining-list) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop (cdr rema= ining-list)))]))))) >>> ~~~~ >>> >>> ~~~~TEST~~~~ >>> (let ([a '(9 10)] >>> =C2=A0 =C2=A0 =C2=A0 [b '(9 10)]) >>> =C2=A0 (test-equal "make-multiple-list-remover-03" >>> =C2=A0 =C2=A0 `(1 2 (3) (4) ,a) >>> =C2=A0 =C2=A0 ((make-multiple-list-remover eq?) >>> =C2=A0 =C2=A0 =C2=A0`(a b (c) (d) ,a) b))) >>> ~~~~ >>> >>> I was wondering, why the test fails. I think (eq? ...) should not be >>> able to see the equivalence of both lists a and b, just like when >>> defined using (define ...). >>> >>> I can also run it in the REPL and see the difference: >>> >>> ~~~~ >>> (define a '(9 10)) >>> (define b '(9 10)) >>> ((make-multiple-list-remover eq?) >>> =C2=A0`(a b (c) (d) ,a) b) >>> $4 =3D (a b (c) (d) (9 10)) >>> >>> (let ([a '(9 10)] >>> =C2=A0 =C2=A0 =C2=A0 [b '(9 10)]) >>> =C2=A0 ((make-multiple-list-remover eq?) >>> =C2=A0 =C2=A0`(a b (c) (d) ,a) b)) >>> $5 =3D (a b (c) (d)) >>> ~~~~ >>> >>> Somehow the bindings of let seem to be different from the bindings >>> created using define. What about using define inside let? >>> >>> ~~~~ >>> >>> ~~~~ >>> --=20 >>> repositories: https://notabug.org/ZelphirKaltstahl >> Somehow the bindings of let seem to be different from the bindings >> created using define. What about using define inside let? >> >> ~~~~ >> (let ([unrelated 'bla]) >> =C2=A0 (define a '(9 10)) >> =C2=A0 (define b '(9 10)) >> =C2=A0 ((make-multiple-list-remover eq?) >> =C2=A0 =C2=A0`(a b (c) (d) ,a) b)) >> $7 =3D (a b (c) (d)) >> ~~~~ >> >> So there the define usage also differs from when I use define on the top >> level. Perhaps that is the difference? On which level the bindings are >> defined? >> >> Regards, >> Zelphir >> -- Stefan Schmiedl EDV-Beratung Schmiedl, Berghangstr. 5, 93413 Cham B=C3=BCro: +49 (0) 9971 9966 989, Mobil: +49 (0) 160 9981 6278