Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is WITH-STANDARD-IO-SYNTAX macro for?

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?

like image 421
prosseek Avatar asked Oct 02 '10 01:10

prosseek


1 Answers

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

like image 199
Daniel Dickison Avatar answered Sep 28 '22 09:09

Daniel Dickison