[plt-dev] overriding constructor style printing

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Mar 3 16:00:49 EST 2009

At Tue, 3 Mar 2009 15:39:54 -0500, Felix Klock's PLT scheme proxy wrote:
> Example Code to illustrate what I am talking about:
> 
> ;;; FILE: bug.ss
> #lang scheme
> (provide external)
> (require mzlib/pconvert)
> ; (install-converting-printer)
> (define-struct internal (value) #:transparent)
> (define (external v) (make-internal v))
> (current-print-convert-hook
>   (let ((old-hook (current-print-convert-hook)))
>     (lambda (v basic-convert sub-convert)
>       (if (internal? v)
>           `(external ,(sub-convert (internal-value v)))
>           (old-hook v basic-convert sub-convert)))))
> ;;; END OF FILE bug.ss
> 
> ;;; FILE: bug2.ss
> (require "bug.ss")
> 
> ;; EXPRESSION       DESIRED-OUTPUT        ACTUAL-OUTPUT
> (external 3)    ;   (external 3)          (make-internal 3)
> 
> ;;; END OF FILE bug2.ss


I think you want to implement the `prop:print-convert-constructor-name'
property:

 #lang scheme
 (provide external)
 (require mzlib/pconvert-prop)
 (define-struct internal (value) #:transparent
   #:property prop:print-convert-constructor-name 'external)
 (define (external v) (make-internal v))



Posted on the dev mailing list.