Best way to find records in sequences?
Very often I create nested sequences where each record have an unique
index identifying that particular record. Lets say I created a list of
possible error messages in my code;
MyErrors =
{"Syntax error", "Out of memory", "Too much tobacco in keyboard"}
When I want to use a particular error somewhere in the code, I have to
know it's position in the sequence. Now, this error list could be updated
over time as I remember more errors that should have been in it - and
it would be best to add those in the end of the sequence - otherwise the
already existing references to the messages would be wrong.
But, I like to group information together to make it as tidy as possible -
and to make it easy to find it at a later stage. This means that often I
INSERT new elements (in this case - new error messages) inside the sequence,
and not at the end. This ofcourse screws up my code since it would usually
refer to a specific record id to show the correct error.
Lets say I wanted to add a "Memory leak detected" error - I would find a
suitable place in the sequence;
MyErrors = {
{"Syntax error", "Out of memory", "Memory leak detected",
"Too much tobacco in keyboard"}}
So - to keep memory messages "grouped", I insert it as the 3rd record. Any
code that refers to MyErrors[3] would now show a memory leak message
instead of "Too much tobacco..".
Now over to indices - lets do some change to MyErrors;
MyErrors = {
--
{"SYN_SE", "Syntax error" },
"ARY_OB", "Out of range" },
"MEM_OO", "Out of memory" },
"MEM_LD", "Memory leak detected" },
"TOB_TM", "Too much tobacco in keyboard"}}
My problem is that match and find don't work on these, so what I've done
is to make an index table that lists all indices in a "flat" sequence;
MyErrIdx = {"SYN_SE", "ARY_OB", "MEM_OO", "MEM_LD", "TOB_TM"}.
This would ofcourse have to correspond to the same record id as in MyErrors.
Questions;
Do any of you think in the same direction, or am I way off here?
Is there a better way to do this?
Kenneth
PS! Just in case you where wondering; I do have code that checks if there
are duplicate indices - so that won't be a problem. :)
Oh, by the way, I don't smoke...
|
Not Categorized, Please Help
|
|