[racket] Generics and gen:custom-write
Anyone has an answer to this?
Thanks,
Laurent
On Tue, Nov 12, 2013 at 1:58 PM, Laurent <laurent.orseau at gmail.com> wrote:
> I'm trying to implement a custom writer for a struct with generics, but I
> think I'm misunderstanding something.
>
> 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:
>
> #lang racket
> (require racket/generic)
>
> (struct A (x y)
> #:transparent
> #:methods gen:custom-write
> [(define/generic super-write write-proc)
> (define (write-proc a port mode)
> (case mode
> [(#t) (write (list (A-x a) (A-y a)) port)]
> [(#f) (display (list (A-x a) (A-y a)) port)]
> [else (super-write a port mode)]))])
>
> (define a (A 1 'b))
> (displayln a) ; ok
> (write a)(newline) ; ok
> (print a)(newline) ; infinite loop
>
> What's the correct way to do that then?
>
> Thanks,
> Laurent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131202/f8f56235/attachment.html>