[racket] Get a list of provided definitions as list of symbols?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jun 16 01:47:33 EDT 2014

You can use `module->exports` to get all the `provide`d names.

To get all the definitions inside the module, use `module->namespace`
after instantiating the module, and then namespace-specific functions.

 > (module m racket
       (provide (all-defined-out))
       (define CONSTANT 42)
       (define function (lambda (x) 'foo))
       (struct banana (dna)))
 > (module->exports ''m)
 '((0
    (CONSTANT ())
    (banana-dna ())
    (banana? ())
    (function ())
    (struct:banana ())))
 '((0 (banana ())))
 > (require 'm)
 > (define ns (module->namespace ''m))
 > (namespace-mapped-symbols ns)
 ; ... a long list, since it includes imported names ...


At Sun, 15 Jun 2014 12:40:01 -0400, Daniel Brady wrote:
> Hi all,
> 
> Is it possible to, after requiring a particular module, get a list of all
> the definitions provided by that module?
> 
> For instance,  can I do something like this?
> > (module m racket
>     (provide (all-defined-out))
>     (define CONSTANT 42)
>     (define function (lambda (x) 'foo))
>     (struct banana (dna)))
> > (require 'm)
> > (all-defined-from 'm)
> '(CONSTANT function banana)
> 
> I realize I could do this simply by defining all-defined-from-m inside my
> module such that it returns a hard-coded list of symbols, but that's not a
> general solution and wouldn't work if wanted the definitions from a module
> I hadn't defined.
> 
> -- 
> *SEE YOU SPACE COWBOY...*
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.