WITH-STANDARD-IO-SYNTAX — 표준 I/O 문법 환경 매크로
WITH-STANDARD-IO-SYNTAX — 표준 I/O 문법 환경 매크로
한 리스프에서 저장한 자료를 그대로 다시 읽어야 할 때가 많아요. 그런데 *print-* 변수나 *read-* 변수 값이 바뀌어 있으면, 출력한 것을 나중에 못 읽는 상황이 생겨요. 그래서 '어떤 환경에서도 똑같이 읽고 쓸 수 있는 표준 상태'로 모든 제어 변수를 묶어 주는 매크로가 바로 with-standard-io-syntax예요. 이 문서는 매크로(macro) 문서예요.
본문
문법 (Syntax)
with-standard-io-syntax form* => result*
인자와 값 (Arguments and Values)
forms— implicit progn이에요.results—forms가 반환하는 값들이에요.
설명 (Description)
forms 본문의 dynamic extent 안에서 모든 reader/printer 제어 변수(이 표준에 명시되지 않은 구현 정의 변수 포함)가 표준 read/print 동작을 만들어 내는 값으로 바인딩돼요. 이 표준이 지정하는 변수들의 값은 다음 그림과 같아요.
| 변수 | 값 |
|---|---|
*package* |
CL-USER 패키지 |
*print-array* |
t |
*print-base* |
10 |
*print-case* |
:upcase |
*print-circle* |
nil |
*print-escape* |
t |
*print-gensym* |
t |
*print-length* |
nil |
*print-level* |
nil |
*print-lines* |
nil |
*print-miser-width* |
nil |
*print-pprint-dispatch* |
표준 pprint 디스패치 테이블 |
*print-pretty* |
nil |
*print-radix* |
nil |
*print-readably* |
t |
*print-right-margin* |
nil |
*read-base* |
10 |
*read-default-float-format* |
single-float |
*read-eval* |
t |
*read-suppress* |
nil |
*readtable* |
표준 readtable |
이 값들은 Figure 23-1. 특정 표준 제어 변수의 값에 해당해요.
예제 (Examples)
파일에 저장했다가 다른 리스프에서 다시 읽는 전형적인 패턴을 볼게요.
(with-open-file (file pathname :direction :output)
(with-standard-io-syntax
(print data file)))
;;; ... Later, in another Lisp:
(with-open-file (file pathname :direction :input)
(with-standard-io-syntax
(setq data (read file))))
어느 쪽에서도 with-standard-io-syntax로 같은 환경을 만들어 두기 때문에, 이 파일은 어느 리스프 구현에서든 표준 방식으로 다시 읽을 수 있어요.
영향받는 요소 (Affected By)
없음.
예외 상황 (Exceptional Situations)
없음.
더 알아보기 (See Also)
없음.
참고 (Notes)
없음.