Thanks for the answer, rapid as always. Jos -----Original Message----- From: Matthew Flatt [mailto:mfl...@cs.utah.edu] Sent: miércoles, 02 de septiembre de 2015 2:11 To: Jos Koot Cc: 'racket users'; jos.k...@gmail.com Subject: Re: [racket-users] custom-print called twice?
The first call is to detect sharing, and the second time is to actually print. For example, if you change `(constr 'y)` to (define b (box #f)) (set-box! b (constr b)) b then you'll see that the output starts with "#0=", because the first pass detected that a "#0#" will be needed. At Wed, 2 Sep 2015 00:45:43 +0200, "Jos Koot" wrote: > Question: > > why is in the following example the custom-printer called twice? > > #lang racket > > (define n 0) > > (letrec-values > (((printer) > (λ (obj port mode) > (set! n (add1 n)) > (fprintf port "#<x:~s>" (name obj)))) > ((id constr pred acc mut) > (make-struct-type 'x #f 1 0 #f > (list (cons prop:custom-write printer)))) > ((name) (make-struct-field-accessor acc 0 'name))) > (constr 'y)) ; -> #<x:y> > > n ; -> 2 > > ;Done with > ;DrRacket, version 6.2.0.5--2015-07-06(d6fa581/a) [3m]. > ;Language: racket [custom]; memory limit: 2000 MB. > > Best wishes, Jos Koot > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an email > to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.