| Donal K. Fellows 2006-06-26, 7:07 pm |
| Alex wrote:
> Sounds like redundancy / behavior duplication to me...
> Any hope of factoring out ?
> In a language with smart macros (a la Lisp), I'd define [switch] as a
> macro emitting a series of
> ... elseif {[regexp {...} $__value]} { } ...
> then all the regexp optimization/degenerate cases would, as usual, be
> done by the normal compilation of [regexp].
Apart from one or two very subtle issues relating to variables (i.e.
[info locals] and [trace]) you're right. But just because it could be
done doesn't mean that it is done. And the chained [if] solution
precludes the jump table stuff unless you do a lot of (usually useless)
optimization work. To cap it all, writing a proper optimizer for the Tcl
bytecode system is probably very difficult at the moment (some of the
design decisions taken back in Tcl 8.0 were sub-optimal).
It's all rather messy.
Donal.
|