> On Nov 12, 2018, at 2:11 PM, Andrew Wilcox <andrew.wil...@gmail.com> wrote:
> 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.

Perhaps you seek a runtime path?

; eval-example.rkt
#lang racket

(provide eval-example)

(require racket/runtime-path)
(define-runtime-path example "example.rkt")

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

(parameterize ((current-namespace example-namespace))
  (namespace-require example))

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

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