After having received a lot of helpful advice in the thread staring with Avoiding if/else knots, I have decided to go for the dispatch table approach. However, even though I don't really have the problem of non-integer ranges, I still don't want to have to construct a table with around, say, 60 combinations of which only around, say, 20 are distinct. So maybe "A|*|*|*" maps to Case 1, "B|A|*|*" maps to Case 2, "B|B|*|*" maps to Case 3, etc.
To get around this I thought I would just use regexps to match groups of conditions and map them onto a set of generic keys which represent the unique cases. Thus for a given case, I would dynamically create a string of delimited fields from the current conditions and then try to match certain parts of the string. In the matching case I would then set the generic key, otherwise I would try the next match. As the cases are all disjoint from the point of view of pattern matching, the order in which I do the matching is not important. Can anyone see any possible drawbacks to this approach?
Thanks,
In reply to Avoiding if/else knots II by loris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |