[plt-scheme] slatex and including unit testable code

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Wed May 16 10:56:58 EDT 2007

On Wed, 16 May 2007, Robby Findler wrote:

> Well, you probably wouldn't need to hack the parser to go that route. 
> You can use read-syntax to get a version of the file as a value that has 
> the source locations in it and then reconstruct things from there. Not 
> trivial, but at least you can rely on the manuals for help :)

Hi Grant,

Here's an example that may help you get started:

(module example-with-syntax-reprinter mzscheme
   (require (lib "etc.ss")
            (planet "syntax-reprinter.ss"
                    ("dyoo" "syntax-reprinter.plt" 1)))

   (define (make-sample-port)
         ((define sample-port (open-input-string #<<HERE
(define (hello world)
   (printf "Hello, ~a"

(define (goodbye)
   (printf "Goodbye!"))
       (port-count-lines! sample-port)

   ;; find-defn: symbol input-port -> (union syntax #f)
   ;; Looks for a defined function in defun-style syntax.
   (define (find-defn name port)
     (let loop ([stx (read-syntax #f port)])
       (cond [(eof-object? stx)
              (syntax-case stx ()
                [(define (name-stx args ...) body ...)
                 (and (symbol? (syntax-e #'name-stx))
                      (symbol=? (syntax-e #'name-stx)
                 (loop (read-syntax #f port))])])))

   (syntax-reprint (find-defn 'goodbye (make-sample-port)))
   (syntax-reprint (find-defn 'hello (make-sample-port))))

Best of wishes!

Posted on the users mailing list.