<div dir="ltr">You're right, that did it--and `shared' gives me what I expect with s/set/seteq/ as well. Many thanks!<div><br></div><div><div>> (shared ([v0 (vertex 0 (seteq) succs0)]</div><div> [v1 (vertex 1 preds1 (seteq))]</div>
<div> [v2 (vertex 2 preds2 succs2)]</div><div> [succs0 (seteq v1 v2)]</div><div> [preds1 (seteq v0)]</div><div> [preds2 (seteq v0 v2)]</div><div> [succs2 (seteq v2)])</div>
<div> (values v0 v1 v2))</div><div>#0=(vertex</div><div> 0</div><div> (seteq)</div><div> (seteq</div><div> (vertex 1 (seteq #0#) (seteq))</div><div> #2=(vertex 2 (seteq #0# #2#) (seteq #2#))))</div><div>
#0=(vertex</div><div> 1</div><div> (seteq</div><div> #2=(vertex</div><div> 0</div><div> (seteq)</div><div> (seteq #0# #3=(vertex 2 (seteq #2# #3#) (seteq #3#)))))</div><div> (seteq))</div>
<div>#0=(vertex</div><div> 2</div><div> (seteq</div><div> #1#</div><div> #0#)</div><div> (seteq #0#))</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 26, 2013 at 3:49 PM, Ryan Culpepper <span dir="ltr"><<a href="mailto:ryanc@ccs.neu.edu" target="_blank">ryanc@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It's probably because you're putting mutable data into an equal (hash-based) set, then mutating the data. That changes the keys, which causes problems for the underlying hash table.<br>
<br>
If you change each occurrence of 'set' to 'seteq' below, the program should run.<span class="HOEnZb"><font color="#888888"><br>
<br>
Ryan</font></span><div><div class="h5"><br>
<br>
<br>
On 07/26/2013 05:25 PM, Nicholas Labich wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
I'm running into what I find to be surprising behavior with circular<br>
structures (vertices of a simple graph).<br>
<br>
Graphically (see code below to reproduce):<br>
0 --> 1 ;; no problem<br>
2-+ ;; also no problem<br>
^-+<br>
<br>
But when I try to add an edge between 0 and 2, I hit an infinite loop at<br>
line 88 of racket/set.rkt (in 5.3.3) or line 447 of<br>
racket/private/set-types.rkt (in the latest 5.90.0.2), both of which are<br>
the hash-proc for set's gen:equal+hash.<br>
<br>
Is this the expected behavior (after all, OCaml makes no guarantee of<br>
termination for (=) on circular data)? I'm surprised that the self-edge<br>
on 2 doesn't result in the same. I've also tried to reproduce the same<br>
using `shared', but I'm assuming I still misunderstand its functionality<br>
because the result is not quite what I expect it to be.<br>
<br>
Any insight would be much appreciated.<br>
<br>
Nick<br>
<br>
Welcome to Racket v5.90.0.2.<br>
> (struct vertex (value preds succs) #:mutable #:transparent)<br>
> (define v0 (vertex 0 (set) (set)))<br>
> (define v1 (vertex 1 (set) (set)))<br>
> (set-vertex-succs! v0 (set v1))<br>
> (set-vertex-preds! v1 (set v0)) ;; 0 --> 1<br>
> (equal? v0 (set-first (vertex-preds v1)))<br>
#t<br>
> (define v2 (vertex 2 (set) (set)))<br>
> (set-vertex-preds! v2 (set v2)) ;; 2--+<br>
> (set-vertex-succs! v2 (set v2)) ;; ^--+<br>
> v2<br>
#0=(vertex 2 (set #0#) (set #0#))<br>
;; try to add the already existing set<br>
> (set-vertex-succs! v0 (set-add (vertex-succs v0) v2)) ;; loops and loops<br>
C-c C-c^Cuser break<br>
context...:<br>
.../racket/collects/racket/<u></u>private/set-types.rkt:447:3: hash-proc<br>
.../racket/collects/racket/<u></u>private/set-types.rkt:447:3: hash-proc<br>
.../racket/collects/racket/<u></u>private/set-types.rkt:447:3: hash-proc<br>
.../racket/collects/racket/<u></u>private/set-types.rkt:447:3: hash-proc...<br>
;; try to make a new set instead<br>
> (set-vertex-succs! v0 (set v1 v2))<br>
C-c C-c^Cuser break<br>
context...:<br>
.../racket/collects/racket/<u></u>private/set-types.rkt:447:3: hash-proc<br>
.../racket/collects/racket/<u></u>private/set-types.rkt:447:3: hash-proc<br>
.../racket/collects/racket/<u></u>private/set-types.rkt:447:3: hash-proc<br>
.../racket/collects/racket/<u></u>private/set-types.rkt:447:3: hash-proc...<br>
> (shared ([v0 (vertex 0 (set) succs0)]<br>
[v1 (vertex 1 preds1 (set))]<br>
[v2 (vertex 2 preds2 succs2)]<br>
[succs0 (set v1 v2)]<br>
[preds1 (set v0)]<br>
[preds2 (set v0 v2)]<br>
[succs2 (set v2)])<br>
(values v0 v1 v2))<br>
(vertex 0 (set) (set #0=(vertex 2 (set #0#) (set #0#))))<br>
(vertex 1 (set (vertex 0 (set) (set #0=(vertex 2 (set #0#) (set #0#)))))<br>
(set))<br>
#0=(vertex 2 (set #0#) (set #0#))<br>
;; I must be using `shared' incorrectly...<br>
<br>
<br></div></div><div class="im">
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/<u></u>users</a><br>
<br>
</div></blockquote>
<br>
</blockquote></div><br></div>