Trouble with `set-copy`

11 views
Skip to first unread message

Nathaniel W Griswold

unread,
Dec 8, 2020, 7:19:41 PM12/8/20
to Racket Users
I don’t know if i’m missing something or what, but the following is confusing me:

(let ([test (mutable-seteqv)])
(for* ([i (in-range 1000)]
[j (random 0 1000)])
(set-add! test j))
(let ([test-copy (set-copy test)])
(printf "test-copy=~a\n" (set->list test-copy))
(printf "Equal from stream is ~a\n" (equal? (list->seteqv (set->list test-copy)) test))))

prints something like:
test-copy=(31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0)
Equal from stream is #f
Equal regular is #t


Why is this?

Thanks

Nate

Jon Zeppieri

unread,
Dec 8, 2020, 7:38:53 PM12/8/20
to Nathaniel W Griswold, Racket Users
I think that's this bug
[https://github.com/racket/racket/commit/543dab59640fa5e911443baaadaae471406dbf40],
which should be fixed in 7.9. - Jon
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/ED9A219D-41D8-42BF-9C67-9887ADFB268B%40manicmind.earth.

Nathaniel W Griswold

unread,
Dec 8, 2020, 7:40:07 PM12/8/20
to Jon Zeppieri, Racket Users
Thanks. Switching to 7.9 now.

Nate

Robby Findler

unread,
Dec 8, 2020, 7:43:56 PM12/8/20
to Nathaniel W Griswold, Jon Zeppieri, Racket Users
No, I don't think that's it. The issue is that one is a mutable set and the other isn't, so they aren't equal (even if their elements aren't equal).

> (equal? (mutable-seteqv) (list->seteqv '()))
#f

Maybe you wanted to call list->mutable-seteqv? Or maybe just start with an immutable set?

Robby


Nathaniel W Griswold

unread,
Dec 8, 2020, 7:45:49 PM12/8/20
to Robby Findler, Jon Zeppieri, Racket Users
I think it is something more. The copied set is giving completely different elements. If i loop over the copied set i get 32 values from 0 to like 31, when i have in fact added 1000 random elements to the original set before copying.

Nate
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAL3TdON3V6Qrq3U2xdemoxYzpgXUkDhRsBT3gN%3DYHjZ8aCFfgg%40mail.gmail.com.

Robby Findler

unread,
Dec 8, 2020, 7:47:49 PM12/8/20
to Nathaniel W Griswold, Jon Zeppieri, Racket Users
Right, it is probably both things. I ran your program on yesterday's git build and it still returns #false, but for the mutability reason, not the bug that Jon mentioned.

Robby


Nathaniel W Griswold

unread,
Dec 8, 2020, 7:48:14 PM12/8/20
to Robby Findler, Jon Zeppieri, Racket Users
Ok. Thanks.

Robby Findler

unread,
Dec 8, 2020, 7:52:39 PM12/8/20
to Nathaniel W Griswold, Jon Zeppieri, Racket Users
Sorry for the earlier confusion!
Reply all
Reply to author
Forward
0 new messages