[plt-dev] overriding constructor style printing

From: Felix Klock's PLT scheme proxy (pltscheme at pnkfx.org)
Date: Tue Mar 3 15:39:54 EST 2009

PLT developers-

If I am developing a teachpack that is intended for use with the  
Student languages (Beginning Student et al), how do I override how  
structures I define are printed?

Searching the documentation for "constructor style printing" sent me  
to the mzlib/pconvert library, and I figured out how to achieve this  
when one is using the install-converting-printer procedure to turn on  
constructor style printing.  But then when I tried to require my  
module as a teachpack into Student code, it continued to print using  
the internal structure constructor name.

----

By the way, its really hard to understand the current mzlib/pconvert  
documentation.  But my current hypothesis is that I was wrong to try  
to adapt that library for this goal anyway; it seems like it is  
totally orthogonal to how the Student languages accomplish constructor  
style printing.  So perhaps the mzlib/pconvert library is deprecated  
and the state of its documentation is irrelevant.

----

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

-Felix



Posted on the dev mailing list.