[plt-scheme] . nitpick .
On Sun, 2007-06-10 at 19:07 +0200, Jos Koot wrote:
> For the toplevel:
>
> (require (lib "r5rs" "lang"))
> (current-namespace (module->namespace '(lib "r5rs" "lang")))
Careful: that's not the right way to get a namespace with just the
bindings from some module X. Instead, that gets you everything bound
*inside* module X. It gives you access to the module's unexported
bindings---including everything that it imports. It bypasses contracts
placed on exports with 'provide/contract'. It doesn't do renaming or
prefixing of exports, either. Unfortunately, on this particular module,
it happens not to make a difference, so your code worked.
'module->namespace' is the right solution to only a very small set of
problems. It's the most invasive thing one can do to a module.
Programming environments and testing frameworks can get away with it,
but ordinary programs, even those that deal with namespaces, shouldn't.
Here's one way to get a namespace with only the bindings for a
particular module "X":
;; namespace-from-module : module-name -> namespace
;; Constructs a namespace containing bindings for only the
;; exports of the given module.
(define (namespace-from-module the-module)
(let ([orig-ns (current-namespace)])
(dynamic-require the-module #f) ;; make sure module initialized
(parameterize ((current-namespace (make-namespace 'empty)))
(namespace-attach-module orig-ns the-module)
(namespace-require the-module) ;; import the bindings
(current-namespace))))
Then:
(namespace-from-module '(lib "r5rs.ss" "lang"))
There are many variations on this code. If you want the consumer of the
namespace to be able to set! the value bindings, use
'namespace-require/copy' to import the bindings instead. If you want to
allow macro definitions, you'll need to use
'namespace-transformer-require' to put something in the transformer
environment too. If you want a fresh instantiation of the module, then
remove the call to 'dynamic-require' and only attach '(quote mzscheme)'
instead of 'the-module'. And so on.
Ryan
>
> Jos Koot
>
> ----- Original Message -----
> From: "Grant Rettke" <grettke at acm.org>
> To: "Jos Koot" <jos.koot at telefonica.net>
> Cc: "Anton van Straaten" <anton at appsolutions.com>; "PLT Scheme"
> <plt-scheme at list.cs.brown.edu>
> Sent: Sunday, June 10, 2007 6:56 PM
> Subject: Re: [plt-scheme] . nitpick .
>
>
> > Does that do something like saying that only the r5rs functions will
> > exist in the current name space?
> >
> > On 6/10/07, Jos Koot <jos.koot at telefonica.net> wrote:
> >>
> >> ----- Original Message -----
> >> From: "Grant Rettke" <grettke at acm.org>
> >> To: "Jos Koot" <jos.koot at telefonica.net>
> >> Cc: "Anton van Straaten" <anton at appsolutions.com>; "PLT Scheme"
> >> <plt-scheme at list.cs.brown.edu>
> >> Sent: Sunday, June 10, 2007 6:25 PM
> >> Subject: Re: [plt-scheme] . nitpick .
> >>
> >>
> >> >I wonder why there isn't a r5rs module.
> >>
> >> But there is: (lib "r5rs" "lang")
> >> Jos Koot
> >>
> >>
> >> >
> >> > On 6/10/07, Jos Koot <jos.koot at telefonica.net> wrote:
> >> >> One could set (read-accept-dot #f) as default for language R5RS.
> >> >> Adding (read-accept-dot #f) to .../collects/r5rs/lang.ss does the trick,
> >> >> although another location may be more appropriate.
> >> >> Jos koot
> >> >>
> >> >> ----- Original Message -----
> >> >> From: "Anton van Straaten" <anton at appsolutions.com>
> >> >> To: "PLT Scheme" <plt-scheme at list.cs.brown.edu>
> >> >> Sent: Sunday, June 10, 2007 4:15 PM
> >> >> Subject: [plt-scheme] . nitpick .
> >> >>
> >> >>
> >> >> > Shouldn't the R5RS language level disallow the infix dot syntax?
> >> >> >
> >> >> > As seen in this message:
> >> >> >
> >> >> > http://groups.google.com/group/comp.lang.scheme/msg/40f19cb9863cf28d
> >> >> >
> >> >> > ...someone experimenting can get confused by the infix feature. It
> >> >> > would
> >> >> > be
> >> >> > helpful to be able to respond to that by saying "that's an extension --
> >> >> > use
> >> >> > the R5RS language level if you want to experiment with standard Scheme
> >> >> > behavior". But here, we can't say that.
> >> >> >
> >> >> > Anton
> >> >> >
> >> >> > _________________________________________________
> >> >> > For list-related administrative tasks:
> >> >> > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >> >> >
> >> >>
> >> >> _________________________________________________
> >> >> For list-related administrative tasks:
> >> >> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >> >>
> >> >
> >>
> >>
> >
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme