Lexical context for all-defined-out

16 views
Skip to first unread message

Philip McGrath

unread,
Apr 26, 2017, 7:01:06 PM4/26/17
to Racket Users
I'm working on a #%module-begin variant that provides all module-level bindings, and I'm having trouble finding the right way to give lexical context to all-defined-out.

The issue (IIUC) is that all-defined-out only exports identifiers "that have the same lexical context as the (all-defined-out) form"; however, I want to have #%module-begin introduce all-defined-out, but have it export the identifiers defined by the programmer in the body of the module.

Currently what I'm doing is essentially this:

#lang racket

(module lang racket
  (provide (except-out (all-from-out racket)
                       #%module-begin
                       provide
                       ;all-defined-out ;can't omit this
                       )
           (rename-out [providing-module-begin
                        #%module-begin]))
  (require (for-syntax syntax/parse))
  (define-syntax (providing-module-begin stx)
    (syntax-parse stx
      [(_ body:expr ...)
       #`(#%module-begin
          (provide #,(datum->syntax stx '(all-defined-out)))
          body ...)])))

(module demo (submod ".." lang)
  (define something
    "a value"))

(require (submod "." demo))

something

This almost works — the providing happens correctly — but it requires that the lang module provide all-defined-out, which I don't actually want to be otherwise available.

Is there a way to give all-defined-out the lexical context I'm looking for?

Matthew Flatt

unread,
Apr 26, 2017, 7:27:25 PM4/26/17
to Philip McGrath, Racket Users
The `all-defined-out` macro supports a trick that several non-hygienic
macros use: it uses the scopes on the parentheses around
`all-defined-out` non-hygienically, instead of the scopes on the
identifier.

So, in place of

(datum->syntax stx '(all-defined-out)))

you can use

(datum->syntax stx `(,#'all-defined-out)))

and then you don't have to export `all-defined-out`.
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Philip McGrath

unread,
Apr 26, 2017, 7:59:54 PM4/26/17
to Matthew Flatt, Racket Users
Thanks, that does the trick!

-Philip


> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages