객체 출력
객체 출력 (Object Printing)
클래스 인스턴스가 print, write, display로 어떻게 출력되는지 커스터마이즈하고 싶다면 printable<%> 인터페이스를 구현하면 돼요. 어떤 출력 함수를 다룰지에 따라 writable<%> 같은 더 좁은 인터페이스도 제공돼요.
출처: Racket Reference
본문
클래스 인스턴스가 print, write, display에 의해 출력되는 방식을 커스터마이즈하려면 printable<%> 인터페이스를 구현해요.
value
printable<%> : interface?
printable<%> 인터페이스는 custom-print, custom-write, custom-display 메서드만 포함해요. custom-print 메서드는 두 인자를 받아요: 대상 포트와, 정확한 음이 아닌 정수로 된 현재 quasiquote 깊이예요. custom-write와 custom-display 메서드는 각각 단일 인자를 받는데, 객체를 write하거나 display할 대상 포트예요.
custom-print, custom-write, custom-display 메서드에 대한 호출은 prop:custom-write 속성을 통해 구조체 타입에 붙은 프로시저를 호출하는 것과 유사해요. 특히 재귀 출력은 호출에서의 탈출(escape)을 트리거할 수 있어요.
더 많은 정보는 prop:custom-write를 참고하세요. printable<%> 인터페이스는 interface*와 prop:custom-write로 구현돼요.
value
writable<%> : interface?
printable<%>와 비슷하지만 custom-write와 custom-display 메서드만 포함해요. print 요청은 custom-write로 전달돼요.
더 알아보기
- Object Equality and Hashing — 객체 동등성과 해싱.
- Object Serialization — 객체 직렬화.