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]

Re: A module system question.


Vollmer Marius <mvo@zagadka.ping.de> writes:

> 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.
>

I should've been more clear, I guess (I know about `current-module').

What I need (well, since then I thought up other ways to achieve whatever
I'm trying to achieve, but the pure academic interest remains :-)), is a
way to write `my-module', to be used exactly as shown.

There is one solution, but it's *very* unclean. You can simply redefine
`define' & `define-public', so they will bind the value of (current-module)
to a variable with some agreed-upon name.