Re: A more elegant solution to this problem?
- From: "John Thingstad" <john.thingstad@xxxxxxxxx>
- Date: Sat, 09 Sep 2006 20:49:20 +0200
On Sat, 09 Sep 2006 20:23:53 +0200, <greg.johnston@xxxxxxxxx> wrote:
Here's the basic situation...I have a list of structures (or
dictionary):
(defstruct entry
"A string for the native word, a list of strings for the
translation(s), and a list of strings for the notes."
native
translation
note)
I want a function or macro which returns the value of the dictionary
argument if all entries are removed such
that each argument is either equal to its corresponding value in the
entry or null.
I have:
(defmacro remove-entry (dict nat trans note)
"Returns the value of the dictionary argument if all entries are
removed such
that each argument is either equal to its corresponding value in the
entry or null."
`(remove-if #'(lambda (ent)
(and (or (equal (entry-native ent) ,nat)
(null ,nat))
(or (equal (entry-translation ent) ,trans)
(null ,trans))
(or (equal (entry-note ent) ,note)
(null ,note))))
,dict))
Is this the best way to handle it?
Well I don't see why it's a macro. Seems it should be a function.
Apart from that wouldn't a hash-table be more efficient?
Why do you need to compare all three entries?
Even if you have multiple entries per key wouldn't a bucket
be better? Of cource I don't really know how you intend to use
it or how large your dictionary is so it is hard to say.
But (native, translation) sounds more like a word translation
to me so it sounds quite large.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
.
- Follow-Ups:
- Re: A more elegant solution to this problem?
- From: greg . johnston
- Re: A more elegant solution to this problem?
- References:
- A more elegant solution to this problem?
- From: greg . johnston
- A more elegant solution to this problem?
- Prev by Date: A more elegant solution to this problem?
- Next by Date: MJD (of "Higher Order Perl") on Lisp macros
- Previous by thread: A more elegant solution to this problem?
- Next by thread: Re: A more elegant solution to this problem?
- Index(es):
Relevant Pages
|