S-Expressions

bearophile bearophileHUGS at lycos.com
Thu Jan 24 17:52:25 PST 2013


qznc:

> We're even now ;)
>
> http://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity#D

I have cut some lines, and I have used a more functional style, 
that fits well for this entry. Compared to the C++ entry this D 
entry is nicer.

I greatly prefer the "verbose" option of the Python regex. And 
"g" for regexes should be the default.


This D code:

auto pairs = categories.match(r2)
              .filter!(m => languages.canFind(m[1]))()
              .map!(m => tuple(m[2].to!uint(), m[1].dup))()
              .array();

With a Python-like syntax becomes nicer:

auto pairs = [(r.to!uint, l.dup) for l,r in
               categories.match(r2)
               if l in languages];

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list