[plt-scheme] getting list of identifiers exported by a module?

From: Kimberley Burchett (kim.burchett at gmail.com)
Date: Sun Aug 27 11:46:20 EDT 2006

Is there a good way to get the list of identifiers exported by a
module?  The closest I've found is this snippet:

    ;; instantiate the module so we can call module->namespace on it
    (dynamic-require module-path #f)
     (lambda (id) (not (module-provide-protected? module-path-index id)))
     (namespace-mapped-symbols (module->namespace module-path))))

This works for identifiers that are explicitly defined in the module,
but not for identifers that are exported with provide/rename.  For
example, the following snippet only prints (add).  I'm hoping there's
some way to get (add sub) instead.

(module foo mzscheme
  (define add +)
  (provide add)
  (provide (rename - sub)))
(dynamic-require 'foo #f)
 (lambda (id) (not (module-provide-protected? 'foo id)))
 (namespace-mapped-symbols (module->namespace 'foo)))

Also, while I'm on the subject, is there a reason for the distinction
between module-path and module-path-index?  The decision of when to
require one versus the other seems somewhat arbitrary to me.

Kimberley Burchett

Posted on the users mailing list.