* access of global variables from modules
@ 2002-03-30 22:43 Mr. Peter Ivanyi
2002-04-01 14:26 ` Neil Jerram
0 siblings, 1 reply; 4+ messages in thread
From: Mr. Peter Ivanyi @ 2002-03-30 22:43 UTC (permalink / raw)
Hello again,
I have another problem with modules.
If I have a module can the module access "global" variables.
I have an application, which defines some global variables.
The application also loads some modules and I would like to access
the global variables from the module.
How can I do it ? (I think I can put the global variables into a module
and another module can depend on it, but isn't there another way ?)
For example I have this module (gen.scm):
----------------------
(define-module (gen gen))
(export gen-hello)
(define (gen-hello)
(set! *G* 3)
(display "Hello World !")
(newline)
)
-------------------------
then I receive this
-------------------------
peteri@mercury $ guile
guile> (define *G* 1)
guile> (use-modules (gen gen))
guile> (gen-hello)
./gen/gen.scm:7:1: In expression (set! *G* 3):
./gen/gen.scm:7:1: Unbound variable: *G*
ABORT: (unbound-variable)
Type "(backtrace)" to get more information or "(debug)" to enter the debugger.
guile>
-------------------------
instead of setting *G* to 3 and then print "Hello World !".
Thanks, for your help in advance.
Peter Ivanyi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: access of global variables from modules
2002-03-30 22:43 access of global variables from modules Mr. Peter Ivanyi
@ 2002-04-01 14:26 ` Neil Jerram
2002-04-01 15:24 ` Mr. Peter Ivanyi
0 siblings, 1 reply; 4+ messages in thread
From: Neil Jerram @ 2002-04-01 14:26 UTC (permalink / raw)
Cc: guile-user@gnu.org
>>>>> "Peter" == Peter Ivanyi <peteri@carme.sect.mce.hw.ac.uk> writes:
Peter> Hello again,
Peter> I have another problem with modules.
Peter> If I have a module can the module access "global" variables.
Peter> I have an application, which defines some global variables.
Peter> The application also loads some modules and I would like to access
Peter> the global variables from the module.
Peter> How can I do it ? (I think I can put the global variables into a module
Peter> and another module can depend on it, but isn't there another way ?)
Peter> For example I have this module (gen.scm):
Peter> ----------------------
Peter> (define-module (gen gen))
Peter> (export gen-hello)
Peter> (define (gen-hello)
Peter> (set! *G* 3)
Peter> (display "Hello World !")
Peter> (newline)
Peter> )
Peter> -------------------------
What exactly do you mean by a global variable? Every variable must be
defined in some module, and in this case what you need to do is:
- export *G* from the module in which it is defined
- in (gen gen), `use' that module.
If you say that *G* is global, you probably mean that it is defined in
the (guile-user) module. So what you need is:
;; ... just after the definition of *G* ...
(export *G*)
;; In gen.scm after the define-module line ...
(use-modules (guile-user))
Please let me know if this helps.
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: access of global variables from modules
2002-04-01 14:26 ` Neil Jerram
@ 2002-04-01 15:24 ` Mr. Peter Ivanyi
2002-04-01 18:29 ` Neil Jerram
0 siblings, 1 reply; 4+ messages in thread
From: Mr. Peter Ivanyi @ 2002-04-01 15:24 UTC (permalink / raw)
> What exactly do you mean by a global variable? Every variable must be
> defined in some module, and in this case what you need to do is:
[...]
> Please let me know if this helps.
>
Aha, now I think I am beginning to get the idea. Yes this definitely
helps. What was confusing for me (and I did not find it in the
documentation which I have) that when I start guile I am already in the
"guile-user" or the "guile" module. That is why I thought there is some
kind of "global" environement and all modules are defined in this
"global" environment.
Thanks again,
Peter Ivanyi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: access of global variables from modules
2002-04-01 15:24 ` Mr. Peter Ivanyi
@ 2002-04-01 18:29 ` Neil Jerram
0 siblings, 0 replies; 4+ messages in thread
From: Neil Jerram @ 2002-04-01 18:29 UTC (permalink / raw)
Cc: guile-user@gnu.org
>>>>> "Peter" == Peter Ivanyi <peteri@carme.sect.mce.hw.ac.uk> writes:
>> What exactly do you mean by a global variable? Every variable must be
>> defined in some module, and in this case what you need to do is:
Peter> [...]
>> Please let me know if this helps.
>>
Peter> Aha, now I think I am beginning to get the idea. Yes this definitely
Peter> helps. What was confusing for me (and I did not find it in the
Peter> documentation which I have) that when I start guile I am already in the
Peter> "guile-user" or the "guile" module. That is why I thought there is some
Peter> kind of "global" environement and all modules are defined in this
Peter> "global" environment.
Great; I hope to be working on the documentation for modules soon, and
I'll make sure to include this point.
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-04-01 18:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-30 22:43 access of global variables from modules Mr. Peter Ivanyi
2002-04-01 14:26 ` Neil Jerram
2002-04-01 15:24 ` Mr. Peter Ivanyi
2002-04-01 18:29 ` Neil Jerram
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).