[plt-scheme] Re: Parameterizing Modules with variables

From: Ed Cavazos (proteus at theworld.com)
Date: Mon Apr 21 02:43:35 EDT 2003

Thanks everyone for the comments and guidance. I have some comments in
response.

Replacing all my "global variables" with parameters is easy
enough. I've known about parameters, but never really used 'em. I
wonder if accessing parameters is slower than referencing
variables. If I have a bunch of references to globals in a tight loop,
maybe calling a function for each parameter reference (if that's what
happens) would add overhead. Minor point...

Another thing that comes to mind is the "visual" difference between:

        (set! *foo* 100)

                and

        (*foo* 100)

This mostly a style thing so I don't expect anyone to necessarily
agree. The 2nd looks like a function call, even though it's a
parameter in the process of being set. "set!" has always been a visual
clue that mutation is a happenin. Now, as long as you know that *foo*
is a parameter, all is well, but even someone unfamiliar with a code
base an immediatley determine that the target of a set! is a
variable. OK, this also a very minor issue. In fact, it's a small
matter of define-syntax to have a more explicit 'parameter
setter'. (Eli's magic solves this).

If those were the only 2 points, I'dve probaby not written this
note. However, a 3rd point came up in my case. I have a toy program,
an implementation of Boids by Craig Reynolds. I have global variables
such as:

        (define *separation-weight* 0.0)
        (define *alignment-weight*  0.0)
        (define *cohesion-weight*   0.0)

Which I can use to modify the behaviour of the flock, on the fly, from
a REPL. I just do a (thread boids) and away we go...

So I read about parameters and they are "thread specific". I can of
course see how this is a virtue in many cases, and a benfit over
variables. However, in the above case, after spawning off a thread I
lose contact with those parameters from my REPL. Right now I'm
thinking that I should launch a GUI from within the thread which will
be my tether to the parameters. Or perhaps a way to launch a REPL that
introspects into the environment of a spawned thread.

Now I'm just ramblin and a response is optional. ;-) Thanks for
reading this far.

Ed



Posted on the users mailing list.