Modifications and try with current module and its used modules
This commit is contained in:
parent
cc7934197e
commit
1109081886
1 changed files with 19 additions and 6 deletions
|
@ -1,14 +1,27 @@
|
||||||
|
(define-module (guile-docs reflection)
|
||||||
|
#:export (current-module-docs
|
||||||
|
pp-module-docs))
|
||||||
|
|
||||||
|
(define (current-module-docs)
|
||||||
|
"Print the docs for the current module as well as all of the modules used by this module."
|
||||||
|
(let* ((cur (current-module))
|
||||||
|
(used (module-uses cur)))
|
||||||
|
(pp-module-docs cur)
|
||||||
|
(map pp-module-docs used)
|
||||||
|
#f))
|
||||||
|
|
||||||
;; Example of how to fetch docs from a module.
|
|
||||||
;; This sort of pattern can be used when we want to scan a given module.
|
|
||||||
(define (pp-module-docs module)
|
(define (pp-module-docs module)
|
||||||
|
"Example of how to fetch docs from a module.
|
||||||
|
This sort of pattern can be used when we want to scan a given module.
|
||||||
|
Input is a module object, not a module name. For that, invoke (resolve-interface '(a module))
|
||||||
|
before passing to this method."
|
||||||
(module-for-each
|
(module-for-each
|
||||||
(lambda (sym var)
|
(lambda (sym var)
|
||||||
(let* ((binding (variable-ref var))
|
(let* ((binding (variable-ref var))
|
||||||
(proc (cond
|
(proc (cond
|
||||||
((procedure? binding) binding)
|
((procedure? binding) binding)
|
||||||
((macro? binding) (macro-binding binding))
|
((macro? binding) (macro-binding binding))
|
||||||
(else "???")))
|
(else #f)))
|
||||||
(docs (procedure-documentation proc)))
|
(docs (when (procedure? proc) (procedure-documentation proc))))
|
||||||
(format #t "-- ~y ~a\n" sym docs)))
|
(format #t "-- ~y ~a\n" sym (or docs ""))))
|
||||||
(resolve-interface module)))
|
module))
|
||||||
|
|
Loading…
Reference in a new issue