[plt-dev] Possible addition to Guide?

From: John Clements (clements at brinckerhoff.org)
Date: Wed Jun 10 13:51:20 EDT 2009

I spent half an hour yesterday trying to read code from a file and  
expand it.  I finally figured it out, but getting all my ducks in a  
row was more painful than expected. Perhaps we could add something  
like this to the Guide somewhere?


Expanding the code in a file:


#lang scheme

(define (expand-from-file dir name)
   (parameterize ([current-load-relative-directory dir]            ;;  
make sure the relative requires work
                  [current-namespace (make-base-empty-namespace)]  ;;  
a fresh namespace for expansion
                  [read-accept-reader #t])                         ;;  
to allow a #lang specification
     (namespace-require 'scheme)                                   ;;  
get 'module' into the current namespace
     (call-with-input-file (build-path dir name)
       (lambda (port)
         (let ([raw-stx (read-syntax name port)])  ;; the raw syntax
         (expand raw-stx))))))

;; pick some random file to expand:
(expand-from-file "/Users/clements/plt/collects/stepper/" "stepper- 
tool.ss")


John

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20090610/54f6ec3a/attachment.p7s>

Posted on the dev mailing list.