Subject: Re: Symbol Properties or Generic Functions
From: (Rob Warnock)
Date: Mon, 18 Nov 2002 03:20:23 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
John Williams  <> wrote:
| A common example is that I want, for example when mapping an
| s-expression to html, to associate some processing with different
| symboles in the s-expression. It seems to me that I can do this in two
| ways - either storing the processing function in a symbol property and
| having subsequent processing functions look that property up or I can
| use a generic function, with methods specialising on the specific
| symbol using EQL.

A third way: Use an explicit hash table (keyed on the symbols) which
contains the processing information. That way you neither pollute the
property lists of the symbols (which can become a performance issue if
the number of properties per symbol gets large) nor twitch any performance
issues (if any) with your CLOS's implementation of EQL specialization.
The values in the hash table could be simply functions, which makes the
tree walk *really* simple!

	(let* ((tag (car sexpr))	; simple case only
	       (proc (gethash tag *html-proc-table*)))
	  (if proc
	    (funcall proc tag sexpr))
	    (error 'html-bad-tag tag sexpr))

Note that this can be an EQ hash table.


Rob Warnock, PP-ASEL-IA		<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607