[plt-scheme] Abstraction in require statements
At Tue, 11 Sep 2007 13:02:08 +0100, Dave Gurnell wrote:
> I would like to be able to do something equivalent to:
>
> (define-syntax (unlib stx)
> (syntax-case stx ()
> [(unlib file)
> #'(planet file ("untyped" "unlib.plt" 2))]))
>
> (require (unlib "list.ss")
> (unlib "string.ss")
> (only (unlib "check.ss") pass fail warn))
>
> Of course, this doesn't work because of the way require is
> implemented, but you get the idea.
>
> I have thought about implementing a require* form that expanded into
> require:
>
> (define-require*-syntax unlib
> ; blah blah blah
> )
>
> (require* (unlib "list.ss")
> (unlib "string.ss")
> (only (unlib "check.ss") pass fail warn))
>
> The idea would be to get define-require*-syntax to store its forms in
> some kind of private namespace, and get require* to search that
> namespace to retrieve the forms. That way, require* forms won't be
> defined in module bodies. Because require* expands into require,
> require* forms should only be able to expand into require forms.
>
> Alas, my macro-fu is weak, and I don't know if this is a realistic
> approach. Also, it's not worth trying to implement something like
> this if there's an existing solution that does the job. Hence this
> email!
Yes. Your `define-require*-syntax' will expand to
(define-syntax (make-require*-macro ...))
and `require*' will use `syntax-local-value' to access require* macros.
Something like this was always the intent with the original `require',
except that we never got around to adding `define-require-syntax' ---
most due to namespace issues. The problem is that binding something
like `rename' for use in `provide' means that `rename' can't be used
anywhere else.
After considering various ways around this problem (including multiple
namespaces and implicit prefixes), I'm included to pick names for the
sub-forms in `require' 4.0 that won't collide anywhere else --- and
then finally add bindings for the built-in forms, as well as
`define-require-syntax' for adding new ones.
Matthew