22.1. Multiple Possible Textual Representations [sec_22-1-1-1]

An additional variable CUSTOM:*PRINT-CLOSURE* controls whether compiled and interpreted functions (closures) are output in detailed form. If CUSTOM:*PRINT-CLOSURE* is non-NIL, a readable syntax is used for closures:

interpreted closures
#S(FUNCTION ...)
compiled closures
#Y(...) (this is what you would see if you open a CLISP #P".fas" in a text editor)

This feature is turned off by WITH-STANDARD-IO-SYNTAX because it is easy to get wrong (see below) and non-portable.

Warning

Closures often refer to value cells or other entities from the lexical environment. The correct operation of a FUNCTION may depend on the access to the same value cells as some other, related FUNCTIONs. If you want to WRITE and READ back FUNCTIONs so that their semantics is preserved, you have to WRITE and READ all FUNCTIONs that share some structure in the lexical environment together, and you have to either bind *PRINT-READABLY* to T or use WITH-STANDARD-IO-SYNTAX:

(SETF (VALUES my-pop my-push)
      `(LET ((storage ()))
         (VALUES (LAMBDA () (POP storage))
                 (LAMBDA (x) (PUSH x storage)))))
(LET ((pair (READ-FROM-STRING
             (WITH-STANDARD-IO-SYNTAX
               (LET ((CUSTOM:*PRINT-CLOSURE* T))
                 (PRIN1-TO-STRING (CONS my-pop my-push)))))))
   (SETQ my-pop-1 (CAR pair)
         my-push-1 (CDR pair)))

Note that my-pop and my-push share environment between themselves but not with my-pop-1 and my-push-1 which can be easily seen if you do

(LET ((CUSTOM:*PRINT-CLOSURE* T) (*PRINT-CIRCLE* T))
  (PRINT (LIST my-pop my-push my-pop-1 my-push-1)))

but which is not at all obvious from the usual #< output.

CUSTOM:*PRINT-CLOSURE* is initially set to NIL.

An additional variable CUSTOM:*PRINT-RPARS* controls the output of the right (closing) parentheses. If CUSTOM:*PRINT-RPARS* is non-NIL, closing parentheses which do not fit onto the same line as the the corresponding opening parenthesis are output just below their corresponding opening parenthesis, in the same column.

CUSTOM:*PRINT-RPARS* is initially set to NIL.

An additional variable CUSTOM:*PRINT-INDENT-LISTS* controls the indentation of lists that span more than one line. It specifies by how many characters items within the list will be indented relative to the beginning of the list.

CUSTOM:*PRINT-INDENT-LISTS* is initially set to 1.

An additional variable CUSTOM:*PPRINT-FIRST-NEWLINE* controls pretty-printing of multi-line objects. When CUSTOM:*PPRINT-FIRST-NEWLINE* is non-NIL, and the current line already has some characters on it, and the next object will be printed on several lines, and it does not start with a #\Newline, then a #\Newline is printed before the object. E.g., when you type (FORMAT T "return value: ~S~%" v) you want want to see a terse one-line output when v is something short (like 0 or NIL or T), but you probably want to see something nice, like

return value:
(long list which does not fit
 on one line)

instead of

return value: (long list which does not fit
 on one line)

when it does not.

CUSTOM:*PPRINT-FIRST-NEWLINE* has no effect if *PRINT-PRETTY* is NIL.

CUSTOM:*PPRINT-FIRST-NEWLINE* is initially set to T.


These notes document CLISP version 2.49Last modified: 2010-07-07