[racket] requiring modules in a namespace
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130103/9669ab89/attachment-0001.html>