0

I am playing around with reflection in Guile (specifically, within GNU Make's guile support) and I wish to obtain the fully qualified path names of every loaded module.

I've found this page in the Guile manual: https://www.gnu.org/software/guile/manual/html_node/Module-System-Reflection.html

But the above doesn't seem to list sufficient functionality to achieve my goal.

I have defined the following Scheme functions to walk the runtime module dependencies:

(define (print-module module indent)
  (display (format #f "~a~a\n" indent module)) )


(define (print-module-trees modules indent)
  (if (not (null? modules))
    (begin
      (print-module-tree (car modules) indent)
      (print-module-trees (cdr modules) indent) ) )
  )

(define (print-module-tree module indent)
  (print-module module indent)
  (print-module-trees (module-uses module) (string-append indent "    ")) )

Then, in my GNUmakefile (after all my scheme modules are loaded) I experimentally run the above with

$(guile (print-module-tree (current-module) ""))

I get the following output:

#<directory (guile-user) 7f3990536c80>
    #<interface (guile) 7f3990481dc0>
        #<interface (ice-9 deprecated) 7f3990481960>
        #<interface (ice-9 ports) 7f39904dee60>
        #<interface (srfi srfi-4) 7f399050e280>
    #<autoload (system base compile) 7f3990536b40>
    #<interface (gnu make) 7f3990536960>
    #<interface (_common-mine) 7f39905d3c80>

My ultimate goal (and the point of this SO question) is to programmatically obtain the FQPN of where each of the above was loaded from (be they source, or pre-compiled module files.)

However, I also have the curious secondary problem that the printed tree above is incomplete. I can accept that perhaps srfi srfi-4 is only loaded once, and so may not be displayed as a direct dependency of my _common-mine. But even still, I have numerous other modules that I've written, that get loaded by _common_mine via (uses-module) that don't display above.

Cognitive Hazard
  • 1,072
  • 10
  • 25

0 Answers0