Re: [Scheme-reports] Write procedure is not backwards compatible
Aaron W. Hsu 06 Jul 2012 21:36 UTC
John Cowan <cowan@mercury.ccil.org> wrote:
> Aaron W. Hsu scripsit:
>
> > Chez Scheme does have WRITE that handles cycles. Specifically, there
> > is a parameter PRINT-GRAPH that controls whether or not WRITE will
> > print the shared structure of the datum or not.
>
> Unless you are doing multiple writes within a single procedure, you are
> going to have to wrap each write in parameterize in order to get the
> correct effect:
>
> (parameterize ((print-graph #t)) (write obj port))
>
> or use #f for #t. Given all that verbosity, I'd just as soon have separate
> write procedures.
The intention is that you can set what you want for any given situation.
Basically, you can do this even with procedure names, but you need at least
three if you want to be useful.
write/safe
write/shared
write/dangerous-stupid-do-not-use-unless-you-think-you-are-neo
Otherwise, the two are pretty equivalent. You can wrap the parameterize up
if you want to, and you can use a parameter to dispatch if you want to do
so. I usually want a safe, standard write, and then occassionally I may
want to print shared structure, but rarely. So, when I do, it is easy and
convenient for me to use a parameter for this.
One convenience of the parameter is that you can set it outside of the
program, rather than having to commit to a specific choice inside. That
could be done by creating your own custom parameter to store the write
procedure that you want to use, so you can achieve the same effect either
way.
--
Aaron W. Hsu | arcfide@sacrideo.us | http://www.sacrideo.us
Programming is just another word for the lost art of thinking.
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports