Re: A more elegant solution to this problem?



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/
.



Relevant Pages

  • Re: number as string in database
    ... each entry (comma delim) is one field ... some entries represent numbers ... but since they start as strings, ...
    (microsoft.public.dotnet.languages.csharp)
  • Data Validation - Prevent Blank Cells
    ... in Data Validation to allow on certain entries (strings ... Can I make sure that an entry is made? ... require VBA module outside of Data Validation. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Substituting the main menu bar(s)
    ... I have tab-separated-value table of strings maintained with Excel, ... with a column for each language. ... All it does is replace the strings according to the translation table. ... the control text in English. ...
    (microsoft.public.vc.mfc)
  • Re: Substituting the main menu bar(s)
    ... I have tab-separated-value table of strings maintained with Excel, with a column for each language. ... All it does is replace the strings according to the translation table. ... I also have a batch file which calls the translation app, and then invokes the compiler on each resource-only DLL project. ...
    (microsoft.public.vc.mfc)
  • Re: GNU gettext
    ... strings in a separate file, ... then a Japanese developer with ja_JP.EUC-JP tries to compile the thing? ... Just explaining that the gettext FAQ is ... I only talking about translation. ...
    (microsoft.public.dotnet.languages.csharp)