[racket] requiring modules in a namespace

From: Jos Koot (jos.koot at gmail.com)
Date: Thu Jan 3 18:12:21 EST 2013

Thanks, Matthew.
Yes, I think make-empty-base-namespace is useful. I'll try it. I was not
aware of its existence. Not needing require in the original namespace allows
me to omit symbol 'require' althogether from my interpreters. Even though
used in quoted form only, it is awkward to have this symbol in the
interpeter without defining it is a primitive macro in the implemented
language. Although this not necessarily breaks meta-recurivity in practice,
it does so in my feeling.   
Thanks, Jos



-----Original Message-----
From: Matthew Flatt [mailto:mflatt at cs.utah.edu] 
Sent: jueves, 03 de enero de 2013 23:29
To: Jos Koot
Cc: users at racket-lang.org
Subject: Re: [racket] requiring modules in a namespace

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.