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: Repeated questions...


Ian Bicking <ian@bickiia.earlhall.earlham.edu> writes:

No idea on the first bit. Maybe the only thing to do right now is
check through the code, or wait for the documentation (there's a small
bit in the guile-doc cvs tree [ref/appendices.texi], but it's not very
complete).

> Second, a question that I brought up a while ago: how can I
> (generically) define a global variable?
> 
> In particular, given a symbol and a value, how can I bind that symbol
> to the value in the global scope?

You should be able to use something like

(define (define-global-symbol sym val)
  (module-define! (current-module) sym val))


Though this isn't completely global. It should be ok, just make sure
that any place you need to use the procs are using the module where
you defined them.


A little test:

guile> (define (define-global-symbol sym val)
  (module-define! (current-module) sym val))
guile> (define (export-proc tcl-context proc-name scheme-name)
   (define-global-symbol (string->symbol scheme-name)
     (lambda (args)
       (run-proc tcl-context proc-name args))))

guile> (define (run-proc . args) (display args))
guile> (export-proc '(1 2 3) "dippy" "weinerdog")
#<variable 40175338 name: weinerdog binding: #<procedure (args)>>
guile> (weinerdog 343)
((1 2 3) dippy 343)


-- 
Greg