[plt-scheme] Problems with pretty-print-print-line

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Tue Jan 8 12:41:55 EST 2008

I'm having some difficulty making the pretty-print library do what I want
it to.

If I put the code

    (module foo mzscheme
      (require (lib "pretty.ss"))

      (printf "testing~n")
      (pretty-print-columns 10)
      (pretty-print '(a b c d))
      (printf "done~n"))

into the definitions window of DrScheme (371.3, module language) and hit
execute, I'd *like* to get the output

    - (a
    -  b
    -  c
    -  d)

(The 4 blank spaces on the left are indentation for email purposes, not
part of the desired output.)

Based on the help desk, it *looks* like the pretty-print-print-line
parameter will do what I want, but I haven't been able to figure out the
right value for this parameter.

If I try

     (lambda (line-no out-port len num-cols)
       (fprintf out-port "~n- ")

with the code above, I get the output


    - (a
    -  b
    -  c
    -  d)
    - done

that is, an extra newline in front of the pretty-printed list, and an extra
prefix at the end.  I figured I could fix these problems by using the
following parameter setting:

     (lambda (line-no out-port len num-cols)
         [(zero? line-no)       ;; for first line
          (fprintf out-port "- ")
         [(not line-no)         ;; for last line
          (fprintf out-port "~n")
         [else                  ;; all other lines
          (fprintf out-port "~n- ")

But that doesn't work either.  Running the above code with this parameter
setting gives me

    - (a
    -  b
    -  c
    -  d)

So, no initial newline, but no REPL prompt either!  Something diverges,
apparently the call to `pretty-print', and I have to kill the evaluation.
Breaking isn't enough.  Before I kill the REPL, the fans on my G5 spin up,
and DrScheme's GC logo flickers, so *something's* clearly happening, just
not anything useful.

Am I missing something in the requirements for pretty-print-print-line's
value, or is there something wrong?

FWIW, I get the same thing from  OS X 10.4.11, PPC.



Posted on the users mailing list.