5
votes

The Practical Common Lisp page 25, explains the WITH-STANDARD-IO-SYNTAX as follows. "It ensures that certain variables that affect the behavior of PRINT are set to their standard values".

The usage is as follows.

(with-open-file (...)
    (with-standard-io-syntax
        (print ...

Should (print) be used in this macro? If not, what would happen?

1

1 Answers

8
votes

Various dynamic variables affect the output produced by print. with-standard-io-syntax ensures those variables are set to the default values.

For example:

(let ((list '(1 2 3 4 5 6 7 8 9 10))
      (*print-length* 5))
  (print list)
  (with-standard-io-syntax
    (print list)))

Prints:

(1 2 3 4 5 ...) 
(1 2 3 4 5 6 7 8 9 10) 

It's particularly important if you're printing things with the intention of being able to read them later (like with prin1).