Random D geekout
Nick Sabalausky
SeeWebsiteToContactMe at semitwist.com
Thu Apr 19 21:23:10 PDT 2012
"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote in message
news:mailman.1953.1334894800.4860.digitalmars-d at puremagic.com...
> I'm writing some code that does some very simplistic parsing, and I'm
> just totally geeking out on how awesome D is for writing such code:
>
Heh, yup :)
I grew up on C/C++ (well, after outgrowing BASIC anyway), and one of the
first things that blew me away about D was its string-processing.
>
> alias void delegate(string key, string value) attrDg;
> attrDg[string] dgs = [
> "name": delegate(string key, string value) {
> d.name = value;
> },
> "phone": delegate(string key, string value) {
> d.phone = value;
> },
> "age": delegate(string key, string value) {
> d.age = to!int(value);
> },
> ... // whole bunch of other stuff to
> // parse different attributes
> ];
Yea, I've done the same trick :) Fantastic stuff. But the one issue I have
with it is that you can't do this:
void delegate()[string] dgs = [
"name": delegate() {
// do stuff
},
"phone": delegate() {
// do stuff
dgs["name"](); // ERR! (Shit!)
// do stuff
}
];
That limitation is kind of annoying sometimes. I think I filed a ticket for
it...
http://d.puremagic.com/issues/show_bug.cgi?id=3995
Ahh, shit, it's been marked invalid :(
>Did I mention I'm totally in love with D?? Seriously. It can handle
>system-level code and "high-level" text-processing code with total
>impunity. What's there not to like?!
Yup. Like, totally. :)
More information about the Digitalmars-d
mailing list