<div dir="ltr">Anyone has an answer to this?<br><br>Thanks,<br>Laurent<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 12, 2013 at 1:58 PM, Laurent <span dir="ltr"><<a href="mailto:laurent.orseau@gmail.com" target="_blank">laurent.orseau@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>I'm trying to implement a custom writer for a struct with generics, but I think I'm misunderstanding something.<br>
<br></div><div>What I want to do is specialize only the behavior for `write' and `display', but leave the behavior for `print' untouched. So I thought that is what define/generic was for, but the following loops indefinitely:<br>
</div><br>#lang racket<br>(require racket/generic)<br><br>(struct A (x y)<br> #:transparent<br> #:methods gen:custom-write<br> [(define/generic super-write write-proc)<br> (define (write-proc a port mode)<br> (case mode<br>
[(#t) (write (list (A-x a) (A-y a)) port)]<br> [(#f) (display (list (A-x a) (A-y a)) port)]<br> [else (super-write a port mode)]))])<br><br>(define a (A 1 'b))<br>(displayln a) ; ok<br>(write a)(newline) ; ok<br>
(print a)(newline) ; infinite loop<br><br></div>What's the correct way to do that then?<br><br></div>Thanks,<br>Laurent<br></div>
</blockquote></div><br></div>