Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.tc.cornell.edu!news3.cac.psu.edu!howland.erols.net!cam-news-hub1.bbnplanet.com!news.bbnplanet.com!su-news-hub1.bbnplanet.com!arclight.uoregon.edu!usenet.eel.ufl.edu!warwick!bris.ac.uk!usenet
From: Nathan Sidwell <nathan@pact.srf.ac.uk>
Subject: table of setf-methods
X-Nntp-Posting-Host: talisker.pact.srf.ac.uk
Content-Type: text/plain; charset=us-ascii
Message-ID: <32D3D3D5.6F8B@pact.srf.ac.uk>
Sender: usenet@fsa.bris.ac.uk (Usenet)
Content-Transfer-Encoding: 7bit
Organization: Partnership In Advanced Computing Technologies
Mime-Version: 1.0
Date: Wed, 8 Jan 1997 17:05:25 GMT
X-Mailer: Mozilla 3.0 (X11; I; SunOS 5.5 sun4u)
Lines: 47

Hi,
I have a structure containing many named flags, ie
(Defstruct flags
	flag1
	flag2
	...
	flagn)

each flag has an associated command line switch (a string) and
I have a list of mappings from string to 'set function', ie

(defconst flag-names
	'(("-flag1"	flags-flag1)
	  ("-flag2"	flags-flag2)
	  ....))

now what I need to do is scan  the command line args (a list
of strings) looking for matches and then set the associated flag
in a global variable. The code similar to,

(setf action (find-flag flag-string))	;; locate the matching flag
;; action will be flags-flag1 etc
(eval `(setf (,action *flags*) t))

Now this uses eval, which I'm led to believe is bad. I'd
like to know a better way of doing what I want. I'm quite happy
for the action to be a function or lambda list so that I can
do (funcall action *flags*), but I can't figureout a non-verbose way
of doing the equivalent of

(defconst flag-names
	`(("flag1" ,#'(lambda (var) (setf (flags-flag1 var) t)))
	  ...))

which I think is what I aught to be doing. I'd like some kind
of macro which expands to the right thing, but can't see how
to do this without evaluating the result of the macro expansion.

Can anyone help?

nathan

-- 
Nathan Sidwell                    The windy road is more interesting
Chameleon Architecture Group at SGS-Thomson, formerly Inmos
http://www.pact.srf.ac.uk/~nathan/                  Tel 0117 9707182
nathan@pact.srf.ac.uk or nathan@bristol.st.com
