One could use a eq hash table (maybe a weak one, or maybe cooperate
more with the code that's doing the printing to throw away the table)
to avoid doing the sensitive code more than once?

Robby


On Fri, Sep 8, 2017 at 9:17 AM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
> There's not a way to turn off the sharing check. Did you find a better
> way to do what you want?
>
> I think the problem here is an implicit contract on values that flow to
> the printer, where the implicit contract constrains a value to be
> printable more than once. A value's printing function can be called
> multiple times not only for the sharing check, but I think it can also
> be called multiple times for speculative printing by the pretty printer
> (where the output may be discarded and tried again after a line break
> is inserted).
>
> At Thu, 31 Aug 2017 10:33:42 -0700 (PDT), Sam Waxman wrote:
>> I wrote a custom printer, and the printer itself has side-effects. As such, I
>> need to be absolutely certain that when I print something, the print function
>> only gets called once.
>>
>> When checking my test cases, things were failing, and then I found out that
>> Racket calls the print function multiple times to check for sharing. How can 
>> I
>> turn this off? I am certain it's not necessary for what I'm printing.
>>
>> The racket documentation states
>>
>> "To avoid a recursive print (i.e., to print without regard to sharing with a
>> value currently being printed), print instead to a string or pipe and 
>> transfer
>> the result to the target port using write-string or write-special."
>>
>> Following the advice here, I changed my print procedure to look like this
>>
>> ;Prints a record
>> (define (rec-print rec port mode)
>>   (define string-port (open-output-string))
>>   (write-string (record-to-string rec) string-port)
>>   (write-string (get-output-string string-port) port))
>>
>> where record-to-string is a function I have that converts a record into a
>> string (without ever calling print or display or any of that)
>>
>> I imagined this would fix my problem, but it did not. The only way I have
>> found to fix my problem is to check if the name of the port is "null" and if
>> so, to not print to it. This is, however, hacky and I'd like something better
>> if possible.
>>
>> --
>> 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.

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

Reply via email to