[prev in list] [next in list] [prev in thread] [next in thread] 

List:       racket-dev
Subject:    [plt-dev] Possible addition to Guide?
From:       clements () brinckerhoff ! org (John Clements)
Date:       2009-06-10 17:51:20
Message-ID: 30766A57-5B1F-418A-87A5-9F4BABB11AAA () brinckerhoff ! org
[Download RAW message or body]

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>

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic