unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Surprising behavior of eq?
@ 2020-09-20 12:16 Zelphir Kaltstahl
  2020-09-20 12:19 ` Zelphir Kaltstahl
  2020-09-20 17:26 ` Taylan Kammer
  0 siblings, 2 replies; 13+ messages in thread
From: Zelphir Kaltstahl @ 2020-09-20 12:16 UTC (permalink / raw)
  To: Guile User

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 = #f

(let ([x '(10 9)]
      [y '(10 9)])
     (eq? x y))
$3 = #t
~~~~

Is this intentional or a bug?

I first noticed something strange when writing the following code:

~~~~DEFINITION~~~~
(define make-multiple-list-remover
  (λ (equal-proc)
    (λ (lst unwanted)
      (let loop ([remaining-list lst])
        (cond
         [(null? remaining-list)
          '()]
         [(equal-proc (car remaining-list) unwanted)
          (loop (cdr remaining-list))]
         [else
          (cons (car remaining-list)
                (loop (cdr remaining-list)))])))))
~~~~

~~~~TEST~~~~
(let ([a '(9 10)]
      [b '(9 10)])
  (test-equal "make-multiple-list-remover-03"
    `(1 2 (3) (4) ,a)
    ((make-multiple-list-remover eq?)
     `(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?)
 `(a b (c) (d) ,a) b)
$4 = (a b (c) (d) (9 10))

(let ([a '(9 10)]
      [b '(9 10)])
  ((make-multiple-list-remover eq?)
   `(a b (c) (d) ,a) b))
$5 = (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?

~~~~

~~~~

-- 
repositories: https://notabug.org/ZelphirKaltstahl



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-09-20 21:42 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-20 12:16 Surprising behavior of eq? Zelphir Kaltstahl
2020-09-20 12:19 ` Zelphir Kaltstahl
2020-09-20 12:58   ` Christopher Lemmer Webber
2020-09-20 13:09   ` Zelphir Kaltstahl
2020-09-20 13:52     ` John Cowan
2020-09-20 15:37       ` Zelphir Kaltstahl
2020-09-20 16:18         ` tomas
2020-09-20 17:05         ` John Cowan
2020-09-20 20:51           ` Linus Björnstam
2020-09-20 21:42             ` John Cowan
2020-09-20 13:57     ` Stefan Schmiedl
2020-09-20 15:42       ` Zelphir Kaltstahl
2020-09-20 17:26 ` Taylan Kammer

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).