Fast switching..
Georg Wrede
georg at nospam.org
Wed Jun 11 03:54:15 PDT 2008
Regan Heath wrote:
> Hi all,
>
> I've been AWOL from this NG for a while but recently a friend of mine
> sent me a link to this:
> http://blogs.msdn.com/jomo_fisher/archive/2007/03/28/fast-switching-with-linq.aspx
>
> and my first thought was; can something similar (or even better) be done
> in D. :)
>
> I admit, I haven't even spent 5 mins thinking about how I might do it,
> but I've never been particularly good with the compile time features of
> D so I figured I'd post something here and see what the people who are
> good at it can come up with.
>
> So, consider this a little challenge .. it may turn out to be trivial,
> it might not, I have no idea.
A language that allows you to write switch statements with strings
should have this built-in. But that is actually a quality of
implementation issue, and therefore transparent to the spec.
In real life, if I were to tackle this and there were less than two
dozen words, I'd figure it out manually. This would also allow for
optimizations, like if I expect some of the words to occur more often
than others.
If this is something I expect to come across regularly, I'd write a
small D program that takes as input a list of words with their number
and another number that hints at how often I expet the word. This
program would output the bit of D source code that I'd paste into my
application.
---
There ought to be a site collecting code snippets, idioms, and tiny
utility programs that help in programming. And with good search
capabilities.
More information about the Digitalmars-d
mailing list