[gambit-list] Thinking of changing pp

Marc Feeley feeley at iro.umontreal.ca
Sun Jun 1 12:21:34 EDT 2008


As you know Gambit has two pretty printing procedures which differ in  
the default output port:

   (pp obj [port])           ;; port defaults to REPL output port
   (pretty-print obj [port]) ;; port defaults to current output port

The rationale is that pretty printing may be part of the program's  
normal behavior or be used for debugging.  In the latter case you want  
the output to go to the REPL's output port (remember that stdout/ 
stderr could have been redirected by the user as part of the program's  
function so they can't be used for user interaction).

But I notice that I often need to pretty print more than one value,  
and I typically add labels to the values, for example:

   (pp (list foo: foo bar: bar))

This is tedious.  Moreover I often add a call to pp to print the  
result of a function, and I want the result to be returned so I end up  
transforming:

(define (square x)
   (* x x))

into

(define (square x)
   (let ((result (* x x)))
     (pp result)
     result))

So I'm thinking of transforming pp into a special form which  
automatically adds keyword labels (when no keyword is explicitly  
given) and returns the value of the last expression.  So you could do

(define (square x)
   (pp x result: (* x x)))

and get as output:

x: 10
result: 100

Perhaps I shouldn't change pp and instead use a different short name,  
but which one?  It could be a special symbol, for example:

(define (square x)
   (& x result: (* x x)))

But special symbols are in short supply and best left for future  
extensions and user needs.  That's why I like pp.  It is easy to type  
and the meaning is clear.

What do you think?

Marc




More information about the Gambit-list mailing list