diff --git a/collects/scheme/provide.ss b/collects/scheme/provide.ss index fe23f61825..3351563f7e 100644 --- a/collects/scheme/provide.ss +++ b/collects/scheme/provide.ss @@ -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)))])))) diff --git a/collects/scheme/require.ss b/collects/scheme/require.ss index 45032bd987..20effb454f 100644 --- a/collects/scheme/require.ss +++ b/collects/scheme/require.ss @@ -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))])))) diff --git a/collects/scribblings/reference/syntax.scrbl b/collects/scribblings/reference/syntax.scrbl index 2a80c8ec6b..cbac85aae5 100644 --- a/collects/scribblings/reference/syntax.scrbl +++ b/collects/scribblings/reference/syntax.scrbl @@ -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]}