[plt-scheme] using except-out with prefix-out

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 14 16:17:41 EDT 2008

At Mon, 14 Apr 2008 15:50:38 -0400, Doug Orleans wrote:
> I want to make a module that re-exports all the bindings from another
> module, but with some of them wrapped.  I tried something like the
> following:
>   #lang scheme
>   (require (except-in "foo.ss" foo))
>   (require (prefix-in unwrapped: (only-in "foo.ss" foo)))
>   (provide (except-out (all-from-out "foo.ss")
> 		       (prefix-out unwrapped: foo)))
>   (provide foo)
>   (define (foo x) (cons 'wrapped (unwrapped:foo x)))
> But this produces the following error:
> wrap-foo.ss:6:21: except-out: identifier to remove `foo' not included
> in nested provide spec at: (all-from-out "foo.ss") in: (except-out
> (all-from-out "foo.ss") foo)
> If I replace `(prefix-out unwrapped: foo)' with `unwrapped:foo' then
> it works fine, i.e. `unwrapped:foo' is not exported.  But I would
> rather not have to hardcode the prefix onto `foo'-- the idea is that
> there are a bunch of bindings that get wrapped, not just `foo'.  Is
> this how prefix-out is supposed to work?  Is there a better way to do
> what I want?

`(prefix-out unwrapped: foo)' starts with the `foo' binding within the
module, and then adds `unwrapped:' to its external name. But `foo'
within the module is locally defined, not imported from "foo.ss".

In contrast, the `unwrapped:foo' binding within the module (whose
external name starts out `unwrapped:foo') is imported from "foo.ss".

The underlying source of confusion is that `except-out' needs only
internal bindings to subtract out, but for syntactic convenience, it
allows arbitrary `provide' sub-paths --- from which it ignores external
names. Meanwhile, `prefix-out' adjust only the external names, which
means that it has no effect for `except-out'. For example,

   (prefix-out more-prefix: unwrapped:foo)

works just as well as `unwrapped:foo', since `more-prefix:' is added
only to the external name, which is ignored.


Posted on the users mailing list.