subtract require/provide forms

svn: r8956
This commit is contained in:
Eli Barzilay 2008-03-12 07:14:57 +00:00
parent 1abcf7c313
commit bf3da735a4
3 changed files with 48 additions and 8 deletions

View File

@ -13,3 +13,16 @@
(filter (lambda (e)
(regexp-match? rx (symbol->string (export-out-sym e))))
(expand-export #'spec modes)))]))))
(provide subtract-out)
(define-syntax subtract-out
(make-provide-transformer
(lambda (stx modes)
(syntax-case stx ()
[(_ spec specs ...)
(let* ([subs (map (lambda (spec) (expand-export spec modes))
(syntax->list #'(specs ...)))]
[subs (map (lambda (i) (syntax-e (export-out-sym i)))
(apply append subs))])
(filter (lambda (i) (not (memq (export-out-sym i) subs)))
(expand-export #'spec modes)))]))))

View File

@ -9,11 +9,28 @@
(syntax-case stx ()
[(_ rx spec)
(regexp? (syntax-e #'rx))
(let-values ([(rx) (syntax-e #'rx)]
[(imports sources) (expand-import #'spec)])
(values
(filter (lambda (i)
(regexp-match? rx (symbol->string
(syntax-e (import-local-id i)))))
imports)
sources))]))))
(let ([rx (syntax-e #'rx)])
(define-values [imports sources] (expand-import #'spec))
(values (filter (lambda (i)
(regexp-match? rx (symbol->string
(syntax-e (import-local-id i)))))
imports)
sources))]))))
(provide subtract-in)
(define-syntax subtract-in
(make-require-transformer
(lambda (stx)
(syntax-case stx ()
[(_ spec specs ...)
(let* ([subs (map (lambda (spec)
(let-values ([(imports srcs) (expand-import spec)])
imports))
(syntax->list #'(specs ...)))]
[subs (map (lambda (i) (syntax-e (import-local-id i)))
(apply append subs))])
(define-values [imports sources] (expand-import #'spec))
(values (filter (lambda (i)
(not (memq (syntax-e (import-local-id i)) subs)))
imports)
sources))]))))

View File

@ -1742,6 +1742,10 @@ instead of
match @scheme[regexp]. @scheme[regexp] must be a literal regular
expression (see @secref["regexp"]).}
@defsubform[(subtract-in require-spec subtracted-spec ...)]{
Like @scheme[require-spec], but omitting those imports that are
provided by one of the @scheme[subtracted-spec]s.}
@subsection{Additional @scheme[provide] Macros}
@note-lib-only[scheme/provide]
@ -1754,6 +1758,12 @@ mirrors the @scheme[scheme/require] library.
with an external name that matches @scheme[regexp]. @scheme[regexp]
must be a literal regular expression (see @secref["regexp"]).}
@defsubform[(subtract-out provide-spec subtracted-spec ...)]{
Like @scheme[provide-spec], but omitting exports that are provided
by one of the @scheme[subtracted-spec]s. Note that this form is not
useful by itself: the specified bindings have already been required
so they have no clashes.}
@;------------------------------------------------------------------------
@section[#:tag "#%top-interaction"]{Interaction Wrapper: @scheme[#%top-interaction]}