[racket] requiring modules in a namespace

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jan 3 17:28:43 EST 2013

Method 1 is better, because it doesn't depend on `require' being bound
in the target namespace. For example, you can start with
`(make-empty-base-namespace)' instead of `(make-empty-namespace)', if
that's useful.

At Thu, 3 Jan 2013 23:22:46 +0100, "Jos Koot" wrote:
> In some cases I want a namespace that includes more than racket/base only,
> preferably a namespace that includes all of module racket. For example, a
> base-namespace does not include procedure force (as clearly documented) I
> see two methods to require all of racket into a base-namespace (I imagine
> there are more methods)
>  
> Method 1:
>  
> #lang racket
>  
> (define namespace-1
>  (parameterize ((current-namespace (make-base-namespace)))
>   (namespace-require 'racket)
>   (current-namespace)))
>  
> (eval 'force namespace-1) ; -> #<procedure:force>
>  
> Method 2:
>  
> #lang racket
>  
> (define namespace-2
>  (let ((namespace (make-base-namespace)))
>   (eval '(require racket) namespace)
>   namespace))
>  
> (eval 'force namespace-2) ; -> #<procedure:force>
>  
> I have also seen that nowadays even the following is accepted:
>  
> (eval '(define list 1) (make-base-namespace))
>  
> IIRC this was not accepted in earlier versions.
> The above is in DrRacket's definitions window version
> 5.3.1.10--2012-12-21(8d5a069/a) [3m]. 
>  
> Questions:
> What is preferable? (e.g. method 1 does not require procedure eval)
> Do the methods work under all circumstances?
> Possibly there are differences and pitfalls I have not noticed? 
>  
> My questions stems from the fact that even after many years, I am still
> playing with my own interpreters (meta-recursive and correctly treating tail
> positions). It is handy to have a namespace that provides all primitives I
> need/want. Taking the whole as a namespace is fast and easy, especially when
> testing meta-recursivity. Mods shaddow the namespace or I simply use
> namespace-set-variable-value!
>  
> Thanks, Jos
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.