print-unreadable-object — 읽을 수 없는 객체 출력
print-unreadable-object — 읽을 수 없는 객체 출력
객체의 내부를 전부 출력하기 어렵거나 원하지 않을 때, 대신 #<...> 형태의 짧은 표시를 출력하고 싶어요. print-unreadable-object는 매크로로, 그런 '읽을 수 없는(unreadable)' 출력을 일관된 규칙으로 만들어 줘요.
시그니처
print-unreadable-object (object stream &key type identity) form* => nil
본문
인자와 값
object— 객체이고, 평가돼요.stream— 스트림 지정자(stream designator) 이고, 평가돼요.type— 일반화된 불리언(generalized boolean) 이고, 평가돼요.identity— 일반화된 불리언이고, 평가돼요.forms— 암묵적 progn이에요.
설명
stream에 object의 인쇄 표현을 출력하는데, #<로 시작해서 >로 끝나요. 몸통 forms가 stream으로 출력하는 모든 것은 이 꺾쇠괄호 안에 담겨요. type이 참이면, forms의 출력 앞에 object의 타입에 대한 간단한 설명과 공백 하나가 붙어요. identity가 참이면, forms의 출력 뒤에 공백 하나와 object의 식별자(identity) 표현 — 보통 저장 주소 — 가 따라와요.
type 또는 identity가 주어지지 않으면 그 값은 거짓이에요. 몸통 forms는 생략해도 유효해요. type과 identity가 모두 참인데 몸통 forms가 하나도 없다면, 타입과 식별자를 구분하는 공백 하나만 출력돼요.
예제
;; Note that in this example, the precise form of the output
;; is implementation-dependent.
(defmethod print-object ((obj airplane) stream)
(print-unreadable-object (obj stream :type t :identity t)
(princ (tail-number obj) stream)))
(prin1-to-string my-airplane)
=> "#<Airplane NW0773 36000123135>"
OR=> "#<FAA:AIRPLANE NW0773 17>"
Affected By
없음.
Exceptional Situations
print-readably가 참이면, 아무것도 출력하지 않고 type이 print-not-readable인 오류를 신호해요.
더 알아보기
없음.