<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>It looks to me like you can't specify rational sets with shared:&nbsp;</div><div><br></div><div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">% racket</font></div><div><font class="Apple-style-span" color="#000000">Welcome to Racket v5.90.0.3.</font></div><div><font class="Apple-style-span" color="#000000">&gt; (struct vertex (v s p) #:transparent #:mutable)</font></div><div><font class="Apple-style-span" color="#000000">&gt; (define-values (x y z)</font></div><div><font class="Apple-style-span" color="#000000">&nbsp; &nbsp; (shared ([v0 (vertex 0 (list) succs0)]</font></div><div><font class="Apple-style-span" color="#000000"><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp; [v1 (vertex 1 preds1 (list))]</font></div><div><font class="Apple-style-span" color="#000000"><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp; [v2 (vertex 2 preds2 succs2)]</font></div><div><font class="Apple-style-span" color="#000000"><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp; [succs0 (list v1 v2)]</font></div><div><font class="Apple-style-span" color="#000000"><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp; [preds1 (list v0)]</font></div><div><font class="Apple-style-span" color="#000000"><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp; [preds2 (list v0 v2)]</font></div><div><font class="Apple-style-span" color="#000000"><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp; [succs2 (list v2)])</font></div><div><font class="Apple-style-span" color="#000000">&nbsp; &nbsp; &nbsp; (values v0 v1 v2)))</font></div><div><font class="Apple-style-span" color="#000000">&gt; x</font></div><div><font class="Apple-style-span" color="#000000">#0=(vertex 0 '() (list (vertex 1 '(#0#) '()) #1=(vertex 2 '(#0# #1#) '(#1#))))</font></div><div><font class="Apple-style-span" color="#000000">&gt; y</font></div><div><font class="Apple-style-span" color="#000000">#0=(vertex</font></div><div><font class="Apple-style-span" color="#000000">&nbsp; &nbsp; 1</font></div><div><font class="Apple-style-span" color="#000000">&nbsp; &nbsp; (list #1=(vertex 0 '() (list #0# #2=(vertex 2 '(#1# #2#) '(#2#)))))</font></div><div><font class="Apple-style-span" color="#000000">&nbsp; &nbsp; '())</font></div><div><font class="Apple-style-span" color="#000000">&gt; (set-vertex-s! x (vertex-s y))</font></div><div><font class="Apple-style-span" color="#000000">&gt; x</font></div><div><font class="Apple-style-span" color="#000000">#0=(vertex</font></div><div><font class="Apple-style-span" color="#000000">&nbsp; &nbsp; 0</font></div><div><font class="Apple-style-span" color="#000000">&nbsp; &nbsp; #1='(#0#)</font></div><div><font class="Apple-style-span" color="#000000">&nbsp; &nbsp; (list (vertex 1 #1# '()) #2=(vertex 2 '(#0# #2#) '(#2#))))</font></div></blockquote><br></div><div><br></div><div>Does OCAML allow rational sets? -- Matthias</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><br><div><div>On Jul 26, 2013, at 5:25 PM, Nicholas Labich wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">I'm running into what I find to be surprising behavior with circular structures (vertices of a simple graph).<div><br></div><div>Graphically (see code below to reproduce):</div><div>0 --&gt; 1 ;; no problem</div>

<div>2-+ &nbsp; &nbsp; &nbsp;;; also no problem<br><div>&nbsp;^-+</div><div><br></div><div>But when I try to add an edge between 0 and 2, I hit an infinite loop at line 88 of racket/set.rkt (in 5.3.3) or line 447 of racket/private/set-types.rkt (in the latest 5.90.0.2), both of which are the hash-proc for set's gen:equal+hash.</div>

</div><div><br></div><div>Is this the expected behavior (after all, OCaml makes no guarantee of termination for (=) on circular data)? I'm surprised that the self-edge on 2 doesn't result in the same. I've also tried to reproduce the same using `shared', but I'm assuming I still misunderstand its functionality because the result is not quite what I expect it to be.</div>

<div><br></div><div>Any insight would be much appreciated.</div><div><br></div><div>Nick</div><div><br></div><div><div>Welcome to Racket v5.90.0.2.</div><div>&gt; (struct vertex (value preds succs) #:mutable #:transparent)</div>

<div>&gt; (define v0 (vertex 0 (set) (set)))</div><div>&gt; (define v1 (vertex 1 (set) (set)))</div><div>&gt; (set-vertex-succs! v0 (set v1))</div><div>&gt; (set-vertex-preds! v1 (set v0)) ;; 0 --&gt; 1</div><div>&gt; (equal? v0 (set-first (vertex-preds v1)))</div>

<div>#t</div><div>&gt; (define v2 (vertex 2 (set) (set)))</div><div>&gt; (set-vertex-preds! v2 (set v2)) ;; 2--+</div><div>&gt; (set-vertex-succs! v2 (set v2)) ;; ^--+</div><div>&gt; v2</div><div>#0=(vertex 2 (set #0#) (set #0#))</div>
<div>;; try to add the already existing set</div>
<div>&gt; (set-vertex-succs! v0 (set-add (vertex-succs v0) v2)) ;; loops and loops</div><div>&nbsp; C-c C-c^Cuser break</div><div>&nbsp; context...:</div><div>&nbsp;.../racket/collects/racket/private/set-types.rkt:447:3: hash-proc</div>

<div>&nbsp;.../racket/collects/racket/private/set-types.rkt:447:3: hash-proc</div><div>&nbsp;.../racket/collects/racket/private/set-types.rkt:447:3: hash-proc</div><div>&nbsp;.../racket/collects/racket/private/set-types.rkt:447:3: hash-proc...</div>

<div>;; try to make a new set instead</div><div>&gt; (set-vertex-succs! v0 (set v1 v2))</div><div>&nbsp; C-c C-c^Cuser break</div><div>&nbsp; context...:</div><div>&nbsp; .../racket/collects/racket/private/set-types.rkt:447:3: hash-proc</div>
<div>&nbsp; .../racket/collects/racket/private/set-types.rkt:447:3: hash-proc</div>
<div>&nbsp; .../racket/collects/racket/private/set-types.rkt:447:3: hash-proc</div><div>&nbsp; .../racket/collects/racket/private/set-types.rkt:447:3: hash-proc...</div><div>&nbsp;&nbsp;</div><div>&gt; (shared ([v0 (vertex 0 (set) succs0)]</div>

<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[v1 (vertex 1 preds1 (set))]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[v2 (vertex 2 preds2 succs2)]</div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[succs0 (set v1 v2)]<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[preds1 (set v0)]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[preds2 (set v0 v2)]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[succs2 (set v2)])</div>

<div>&nbsp; &nbsp; (values v0 v1 v2))</div><div>(vertex 0 (set) (set #0=(vertex 2 (set #0#) (set #0#))))</div><div>(vertex 1 (set (vertex 0 (set) (set #0=(vertex 2 (set #0#) (set #0#))))) (set))</div><div>#0=(vertex 2 (set #0#) (set #0#))</div>

<div>;; I must be using `shared' incorrectly...</div></div></div>
____________________<br> &nbsp;Racket Users list:<br> &nbsp;<a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>