[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Aliasing a module variable with a variable from the
Re: [Chicken-users] Aliasing a module variable with a variable from the user ?
Fri, 30 Mar 2007 11:09:04 +0200
2007/3/29, Graham Fawcett <address@hidden>:
On 3/29/07, minh thu <address@hidden> wrote:
> 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
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
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
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
Just before requiring the module ? I prefer the other way too, but it
might be a good idea.