This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
mike@olan.com (Michael N. Livshin) writes: > Is there a way for a function to know in which module it is defined? > > To clarify: > > (define-module (used-module)) > > (define-public (fun) > (my-module)) > ^^^^^^^^^^^ > > (define-module (using-module) > #:use-modules (used-module)) > > (fun) > => returns (used-module) > > Is there any way to write the `my-module' function? Yes. Guile has something called the `current' module. While a certain module is being defined, that module is the current one. However, when a function that is contained in a certain module is actually called, the current module will *not* be the one that the function is contained in. So, the following will work (define-module (used-module)) (define this-module (current-module)) (define (my-module) this-module) (define-public (fun) (my-module)) (define-module (using-module) #:use-module (used-module)) (fun) => returns #<directory used-module 61b98> But this will *not* work: (define-module (used-module)) (define (my-module) (current-module)) (define-public (fun) (my-module))