The less-familiar parts of Lisp for beginners — with-standard-io-syntax

The next feature we’ll discuss is the with-standard-io-syntax macro.  This is probably underused in many contexts, and its absence can lead to some mysterious behaviour in certain circumstances.

You’ll recall that there are dynamic variables that modify the behaviour of the Lisp writer, as we discussed in several articles related to printing.  We also saw variables that modify the behaviour of the Lisp reader, the most obvious of which is the *read-table* dynamic variable.

When writing a function that writes and/or reads, if that function might be called from an unknown context it is strongly recommended that with-standard-io-syntax is used to wrap those input/output operations.  This macro sets the control variables to a set of well-defined defaults.  The programmer can always embed further let forms to tweak these as necessary, but it’s important to start in a known state.

One can imagine the potential for weirdness if a library that manipulates data files with write were called with the *print-base* variable set to, say, 8.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.