Re: Code Feedback Wanted (Generating more garbage)
From: David Sletten (david_at_slytobias.com)
Date: 03/24/04
- Next message: Alexander Schmolck: "Re: Python development tools"
- Previous message: Adam Warner: "Re: Read macros for user interface --- asking for advice"
- In reply to: David Steuber: "Code Feedback Wanted (Generating more garbage)"
- Next in thread: Brian Downing: "Re: Code Feedback Wanted (Generating more garbage)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 24 Mar 2004 12:13:17 GMT
David Steuber 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*))
>
> (defun set-fractional-bits (fb)
> "A nice way to set both *fractional-bits* and *escape-value* at the same time"
> (setf *escape-value* (ash 4 fb)
> *my-two* (ash 2 fb)
> *fractional-bits* fb))
>
I'll let someone with more guts tackle your program in detail, but
here's one suggestion. To avoid 'global' variables, you can create a
closure with local variables and only those functions which need access
to them. For instance:
(let* ((fractional-bits 16)
(escape-value (ash 4 fractional-bits))
(my-two (ash 2 fractional-bits)))
(defun initialize (fb)
(setf escape-value (ash 4 fb) my-two (ash 2 fb) fractional-bits fb))
...)
<Rest of program out here--can't access FRACTIONAL-BITS, etc...>
This gives you the convenience of not having to pass the 'globals' as
args to each function, yet still provides some encapsulation.
You can't change these variables directly from the top-level
interactively, but you do have a setter function--INITIALIZE (or
SET-FRACTIONAL-BITS, whatever you call it).
David Sletten
- Next message: Alexander Schmolck: "Re: Python development tools"
- Previous message: Adam Warner: "Re: Read macros for user interface --- asking for advice"
- In reply to: David Steuber: "Code Feedback Wanted (Generating more garbage)"
- Next in thread: Brian Downing: "Re: Code Feedback Wanted (Generating more garbage)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|