From: Matthew Flatt <mflatt@cs.utah.edu>
To: plt-scheme@web-ext.cs.brown.edu
Subject: [plt-scheme] 299.103
Date: Wed, 27 Apr 2005 09:41:19 -0600

The exp-tagged code in CVS for MzScheme and MrEd is now version 299.103.

This version adds per-struct-type write customization through a
`prop:custom-write’ property.

A value for the property must be a pair of procedures. The first
procedure takes an instance of the structure type and returns
information about its sub-parts to be printed recursively. The second
procedure takes an instance of the structure type and returns
information about how it should be printed (a prefix string, a list of
`recur’, `display’, and `write-special’ instructions, and a suffix
string).

Neither procedure actually writes to a port. By returning information
about how things are printed instead of actually printing, the
custom-write procedures support graph detection and pretty printing.

Example (from the manual):

 (define (tuple-sub-values tuple)
   (tuple-ref tuple 0))

 (define (tuple-print tuple write? special-ok?)
   (values (if write? "<" "")
           (cdr (apply
                 append
                 (map (lambda (elem) `((display . ",") (recur . ,elem)))
                      (tuple-ref tuple 0))))
           (if write? ">" "")))

 (define-values (s:tuple make-tuple tuple? tuple-ref tuple-set!)
   (make-struct-type ’tuple #f 1 0 #f
                     (list (cons prop:custom-write
                                 (cons tuple-sub-values
                                       tuple-print)))))

 (display (make-tuple ’(1 2 "a"))) ; prints: 1 , 2 , a

 (let ([t (make-tuple (list 1 2 "a"))])
   (set-car! (tuple-ref t 0) t)
   (write t))  ; prints: #0=<#0# , 2 , "a">

In addition to adding `prop:custom-write’, a few details have changed
on the read side:

 * Changed `read-syntax[/recursive]’ to remove the delta-list argument,
   and changed the definition of a read handler to remove the
   delta-list argument.

 * Added `relocate-input-port’ to MzLib’s "port.ss". To shift the
   source locations associated with a port, wrap it with
   `relocate-input-port’ (instead of passing deltas to `read-syntax’).

 * Changed `read[-syntax]/recursive’ to produce a special-comment value
   when a comment is parsed, instead of reading the next datum. See the
   readtable section of the docs for an example.

 * Changed `make-input-port’ to take two new arguments: a count-lines!
   procedure (defaults to `void’) and an initial position.

Matthew