2007/3/29, Graham Fawcett <[EMAIL PROTECTED]>:
On 3/29/07, minh thu <[EMAIL PROTECTED]> wrote: > Hi, > > Say I've a module with a bunch of procedures that use a global variable. > Call it *global*. > > Can I use that module and specify that *global* is an alias of *my-global* ? > (So that every procedures of the above module now work actually on *my-global*.)
Hi Graham,
It might be cleaner to use parameters instead: (define *global* (make-parameter #f)) ;; set the value: (*global* *my-global*) ; or whatever ;; use the value (print (+ 3 (*global*)))
That way, *my-global* is only readable via *global*. But it's a good idea, I can set *global*, not to *my-global*, but to a procedure to read/write *my-global* (in fact, another parameter).
If you're not familiar with parameters, it's worth a quick read of the docs (in short, they give you dynamic scoping instead of lexical scoping).
Well I just viewed them as an easy way to have globals.
If you're going to the bother of rewriting all your *global* references to (*global*) instead, I suppose you could cheat and use (define-macro (*global*) '*my-global*) instead. But I'd use parameters.
Just before requiring the module ? I prefer the other way too, but it might be a good idea. Thank you, thu _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
