OT: What's your favorite codeline?

downs default_357-line at yahoo.de
Sun Aug 30 04:14:05 PDT 2009


language_fan wrote:
> Sat, 29 Aug 2009 13:45:23 -0300, Ary Borenszweig thusly wrote:
> 
>> A Bothe escribió:
>>> What's your favorite line of D code?
>>>
>>> My one is
>>> Application.Run();
>> Isn't that C#? :-)
>>
>> I think a favorite line of D code should have a feature of D that
>> doesn't appear in any other language...
> 
> I've heard a d guru known as 'downs' is the master of obfuscated one-
> liners.

Well I wouldn't call myself a 'guru' .. 'mutilator', mebbe :)

That being said, here's the results of a quick grep of my #d log for memorable lines


<downs>       Bignum!(To - From)* slice(int From, int To)() { return cast(Bignum!(To - From)*) ((cast(Type*) this) + From); }

<downs>     struct ZipIterator(A, B) { A a; B b; int length() { return min(a.length, b.length); } Stuple!(typeof(a[0]), typeof(b[0])) opIndex(T...)(T t) { return stuple(a[t], b[t]); } int opApply(C)(C callable) { for (int x = 0; x < length; ++x) { static if (is(typeof(callable(x, a[x], b[x])))) { if (auto res = callable(x, a[x], b[x])) return res; } else { if (auto res = callable(a[x], b[x])) return res; } } return 0; } }

<downs>     class Lévy : LSystem!(8) {
<downs>       mixin(LSysFunc("X -> +X--X+ / step"));

<downs>     Ret!(T[$-1]) delegate(Param!(T[$-1])[T.length - 1 .. $]) bind(T...)(T params) { struct Stuff { T data; Ret!(T[$-1]) call(Param!(T[$-1])[T.length - 1 .. $] rest) { return data[$-1](data[0 .. $-1], rest); } } auto res = new Stuff; foreach (id, value; params) res.data[id] = value; return &res.call; }

<downs>         prettyprint(rand%640, rand%480, Center, rgb(col), Fill = rgb(hsv((col.h + 128) % 255, col.s, col.v)), Format("[size ", rand() % 12 + 8, "] Don't worry, be happy! [/size]"));

<downs>     foo.betweens("src=\"", "\"") /select/ (string s) { return s.find(criteria) != -1; }

<downs>     "/proc/cpuinfo".read().castLike("").between("cpu MHz", "\n").between(": ", "")

<downs>     auto videocon = ctx.getStreams().first(WHERE!("?.codec.codec_type == CodecType.Video")).codec;



More information about the Digitalmars-d mailing list