<div dir="ltr">One useful trick in these situations is to break the computation and then you can sometimes get a stacktrace inside the infinite loop.<div><br>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sat, Mar 1, 2014 at 6:40 AM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@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">
<div class=""><br>
On Mar 1, 2014, at 5:50 AM, Jon Stenerson wrote:<br>
<br>
> When I put the following in the DrRacket definitions window and then evaluate t, it works for a few seconds and runs out of memory. Anyone understand the problem?<br>
><br>
> #lang racket<br>
><br>
> (define (Print stx port mode)<br>
> (if (Atom? stx)<br>
> (write-string "ATOM " port)<br>
> (Print (Pair-cdr stx) port mode)))<br>
><br>
> (struct Base ()<br>
> #:methods gen:custom-write<br>
> [(define write-proc Print)])<br>
><br>
> (struct Atom Base (datum))<br>
> (struct Pair Base (car cdr))<br>
><br>
> (define t (struct-copy Base (Atom 3)))<br>
<br>
<br>
</div>t is _not_ an instance of Atom but Base, which is what the struct-copy expression specifies. When you enter<br>
<br>
> t<br>
<br>
Racket looks for a printer specification. It finds write-proc, which checks Atom? of stx and finds that t is not an Atom. Hence, it extracts Pair-cdr, but t is also not a Pair. Ergo, Pair-cdr raises an exception. The printer needs to print what it found in lieu of a Pair, so Racket looks for a printer specification. It finds write-proc, which ...<br>
<br>
Easiest fix: Change Base in the last line to Atom.<br>
<span class="HOEnZb"><font color="#888888"><br>
-- Matthias<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>