Re: Code Feedback Wanted (Generating more garbage)

From: Brian Downing (see-signature_at_lavos.net)
Date: 03/24/04


Date: Wed, 24 Mar 2004 15:46:59 GMT

In article <m2ekrildgt.fsf@david-steuber.com>,
David Steuber <david.steuber@verizon.net> wrote:
> ;;;; Just for the record, I hate global variables because they
> ;;;; break modularity by being non-local.
>
> ;;; global variables related to the fractional bits in our fixed radix numbers
> (defvar *fractional-bits* 16
> "Number of fractional bits in our number")
> (defvar *escape-value* (ash 4 *fractional-bits*)
> "Numbers larger than this have escaped and are not part of the
> Mandelbrot Set")
> (defvar *my-two* (ash 2 *fractional-bits*))

As dynamic variables go this doesn't seem too bad a usage in my
unlearned opinion. You can say:

(let* ((*fractional-bits* 64)
       (*escape-value* (ash 4 *fractional-bits*))
       (*my-two* (ash 2 *fractional-bits*)))
  (mandelbrot-set ...))

to rebind them only for the dynamic scope of the let*. Since most
implementations treat dynamic scope as thread local, you can even have
multiple threads going at it with different parameters at the same time
with the above. I believe this should help your "breaking modularity"
concerns.

It's been a great surprise to me just how /usable/ dynamic variables
(CL's "globals") are, coming from languages where globals are greatly
feared.

-bcd

-- 
*** Brian Downing <bdowning at lavos dot net>