[plt-scheme] Slideshow and pretty-print

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Nov 26 07:27:50 EST 2007

At Mon, 26 Nov 2007 20:12:42 +0800, yug at ios.ac.cn wrote:
> 1. in slideshow, why code could not print my s-exp good?

Slideshow's `code' layout depends on the layout of the source. To get
the layout information, the source needs to be literally within a
`code' form.

In this example:

>   (define code-test '(code "DrScheme" "DrScheme"
>                            "DrScheme" (break one) (break two) "DrScheme"
> "DrScheme"
>                            (break three) "DrScheme"))
>   (slide/center
>    (code #,code-test))

`code-test' just has an S-expression with no source-layout information,
so `code' cannot format it based on the source.

In the case of

    (code "DrScheme" "DrScheme"
          "DrScheme" (break one) (break two) "DrScheme" "DrScheme"
          (break three) "DrScheme")))

the S-expression to typeset is immediately visible to the `code' macro,
so it can extract source information (at compile time) to decide the

> 2. How can I reserve the annotations when I apply pretty-print ?

I'm not sure I understand the question.

If you want pretty-print to generate the layout, then you can use
`read-syntax' to read an S-expression back out of the `pretty-format'
generated string:

  (code #,(read-syntax 
           (let ([p (open-input-string
                     (parameterize ([pretty-print-columns 10])
                        '(this is a test))))])
             ;; be sure to turn on line counting to get source layout:
             (port-count-lines! p)

But if your question was how to preserve the comment in

  (define test
      '(this is
             a test))
  (define ptest
    (pretty-format test))

then there's no way to do that with just a quoted S-expression. The
comment doesn't exist after the program is parsed.


Posted on the users mailing list.