Wanted to write some very-very simple DSL for a long, time, but only today got an interesting idea and free hour to play. I often been using constructions like switch(obj.typeof) { case Type#: }, but this approach does not work in case of inheritance. So I tried to write some alternative. Here's the result:
There're several disadvantages with this code (like unpredicted order of pattern calling because of unordered map) and overall it is even bigger than using chain of ifs, just wanted to share overall idea
tacticsTue 22 Jun 2010
(like unpredicted order of pattern calling because of unordered map)
ivan Tue 22 Jun 2010
Wanted to write some very-very simple DSL for a long, time, but only today got an interesting idea and free hour to play. I often been using constructions like
switch(obj.typeof) { case Type#: }
, but this approach does not work in case of inheritance. So I tried to write some alternative. Here's the result:output is very predictive:
Implementation is trivial too: Base class
Pattern
:Inheritor:
DSL:
There're several disadvantages with this code (like unpredicted order of pattern calling because of unordered map) and overall it is even bigger than using chain of ifs, just wanted to share overall idea
tactics Tue 22 Jun 2010
See Map.ordered.
ivan Tue 22 Jun 2010
yep, I know about this slot, but I don't know how to write ordered map as Literal :)