[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

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

(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

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

with the code above, I get the output

    testing

    - (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:

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

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

    testing
    - (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 3.99.0.9-svn8jan2008.  OS X 10.4.11, PPC.

Thanks,

Richard


Posted on the users mailing list.