Subject: Re: Special variables, style and packages
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2 Jul 2002 04:04:29 GMT
Newsgroups: comp.lang.lisp
Message-ID: <afr8od$5ho4b$1@fido.engr.sgi.com>
gary <muddy9999_2000@yahoo.com> wrote:
+---------------
| ...dialog boxes for data entry.  I have over 90 data screens...
| (defvar *example-pane* 
|    (make-instance 
|       'capi:column-layout
|       <.... about 40 lines of layout instructions ....> ))
| I feel queasy having so many special variables around.
+---------------

You should feel queasy.  What about defining a single alist or
hash table that contains all your examples?  E.g. [untested]:

	(defvar *capi-examples* (make-hash-table))

	; then lots of these:
	(setf (gethash 'example-pane *capi-examples*)
	  (make-instance
	    'capi:column-layout
	    <...layout instructions...> ))

	...additional SETFs as needed...

	; abstract the lookup (and error check)
	(defun get-capi-example (name)
	  (let ((example (gethash 'example-pane *capi-examples*)))
	    (unless example
	      (error "get-capi-example: example screen not found:" name))
	    example))

Then when you need the "example-pane" again, it's easily found:

	(let ((pane (get-capi-example 'example-pane)))
	  ...do something with pane...)


-Rob

p.s. Note: I originally wrote the above with keywords (":example-pane")
instead of symbols in the current package, but there have been comments
here on the list about not polluting the KEYWORD packages with such stuff.
You can do it either way. Or even make a single separate "CAPI-EXAMPLES"
package with the global hash table name and the hash keys in it, whatever.
Just be warned that I'm not an experienced enough CL programmer to be
giving advice on matters of style at that level...  ;-}

-----
Rob Warnock, 30-3-510		<rpw3@sgi.com>
SGI Network Engineering		<http://www.rpw3.org/>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA

[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]