chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Aliasing a module variable with a variable from the


From: Graham Fawcett
Subject: Re: [Chicken-users] Aliasing a module variable with a variable from the user ?
Date: Thu, 29 Mar 2007 16:21:40 -0400

On 3/29/07, minh thu <address@hidden> 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*.)

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*)))

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

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.

Graham




reply via email to

[Prev in Thread] Current Thread [Next in Thread]