<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>