Suppose I've defined a simple language:

; example.rkt
#lang racket

(provide foo)

(define-syntax foo
  (syntax-rules ()
    ((foo)
     (printf "foo!~n"))))


Now I want to create an eval-example function which will evaluate forms in 
my language:

> (eval-example '(foo)) 
foo! 


If I'm working interactively, this is easy enough:

(define example-namespace (make-base-empty-namespace))

(parameterize ((current-namespace example-namespace))
  (namespace-require "example.rkt"))

(define (eval-example code)
  (parameterize ((current-namespace example-namespace))
    (eval code)))

How about providing eval-example from a module?

; eval-example.rkt
#lang racket

(provide eval-example)

(define example-namespace (make-base-empty-namespace))

(parameterize ((current-namespace example-namespace))
  (namespace-require "example.rkt"))

(define (eval-example code)
  (parameterize ((current-namespace example-namespace))
    (eval code)))


The problem here is that namespace-require is a procedure and so resolves 
"example.rkt" at run time, not at compile time like require would do.  Thus 
"example.rkt" is resolved relative to the current working directory of the 
running program, not relative to the directory containing eval-example.rkt as 
would happen using a require.

How to do this?

Thanks!

Andrew

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to