www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - OT: What's your favorite codeline?

reply A Bothe <info alexanderbothe.com> writes:
What's your favorite line of D code?

My one is
Application.Run();

And yours?

------------------------------------------------------------------------------
PS: Check out my D-IDE at http://www.alexanderbothe.com/?id=27
Aug 29 2009
next sibling parent reply language_fan <foo bar.com.invalid> writes:
Sat, 29 Aug 2009 11:14:15 -0400, A Bothe thusly wrote:

 What's your favorite line of D code?
 
 My one is
 Application.Run();
 
 And yours?

foreach(Problem p; World.problems) find_answer_to(p); It just always seems to get stuck.
Aug 29 2009
parent reply "Manfred_Nowak" <svv1999 hotmail.com> writes:
incognito wrote:

 foreach(Problem p; World.problems) find_answer_to(p);
 
 It just always seems to get stuck.

... because it doesn't have `World.plan' to its disposal.
Aug 29 2009
parent Jeremie Pelletier <jeremiep gmail.com> writes:
Manfred_Nowak Wrote:

 incognito wrote:
 
 foreach(Problem p; World.problems) find_answer_to(p);
 
 It just always seems to get stuck.

... because it doesn't have `World.plan' to its disposal.

You are lacking a world context, cultural semantics, a problem solver, and a very very large pool of random. Maybe an abstract country factory.
Aug 29 2009
prev sibling next sibling parent reply Ary Borenszweig <ary esperanto.org.ar> writes:
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...
Aug 29 2009
next sibling parent reply language_fan <foo bar.com.invalid> writes:
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.
Aug 29 2009
parent reply downs <default_357-line yahoo.de> writes:
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();

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;
Aug 30 2009
parent reply Robert Fraser <fraserofthenight gmail.com> writes:
downs wrote:
 <downs>     foo.betweens("src=\"", "\"") /select/ (string s) { return
s.find(criteria) != -1; }

Heh, I love that infix expression syntax. Too abd it ends up with a completely useless wrapper struct & 2 function calls, but hopefully LDC can inline that out.
 <downs>     auto videocon = ctx.getStreams().first(WHERE!("?.codec.codec_type
== CodecType.Video")).codec;

Heh, going LINQ on us, now?
Sep 01 2009
parent downs <default_357-line yahoo.de> writes:
Robert Fraser wrote:
 downs wrote:
 <downs>     foo.betweens("src=\"", "\"") /select/ (string s) { return
 s.find(criteria) != -1; }

Heh, I love that infix expression syntax. Too abd it ends up with a completely useless wrapper struct & 2 function calls, but hopefully LDC can inline that out.

I'm 90% sure it can. [update] Actually, I just tried and LDC compiles a simple /select/ test to plain, inlined code. [update2] GDC doesn't. [update3] For that matter, neither does DMD. LDC is really shaping up to be the best D compiler out there. It already is on Unix (imho). Now if only they can get win32 exception support to work ..
 <downs>     auto videocon =
 ctx.getStreams().first(WHERE!("?.codec.codec_type ==
 CodecType.Video")).codec;

Heh, going LINQ on us, now?

I _was_ thinking of that :) Could have used ex!() but WHERE is a little denser. (for comparison: ex!("c -> c.codec.codec_type == CodecType.Video") )
Sep 02 2009
prev sibling parent language_fan <foo bar.com.invalid> writes:
Wed, 02 Sep 2009 10:28:58 +0200, downs thusly wrote:

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

Heh, I love that infix expression syntax. Too abd it ends up with a completely useless wrapper struct & 2 function calls, but hopefully LDC can inline that out.

[update] Actually, I just tried and LDC compiles a simple /select/ test to plain, inlined code. [update2] GDC doesn't. [update3] For that matter, neither does DMD. LDC is really shaping up to be the best D compiler out there. It already is on Unix (imho). Now if only they can get win32 exception support to work ..
 <downs>     auto videocon =
 ctx.getStreams().first(WHERE!("?.codec.codec_type ==
 CodecType.Video")).codec;

Heh, going LINQ on us, now?

I _was_ thinking of that :) Could have used ex!() but WHERE is a little denser. (for comparison: ex!("c -> c.codec.codec_type == CodecType.Video") )

This is impressive. You acknowledge that the functional representation is so much better that you actually implement its compiler with the metaprogramming facilities. Imagine, in future, you can just write, mixin compile("SML", ` some code ... `); and all your problems are solved. It's a shame the built-in syntax looks like this crap (T)(T c){ return c; } instead of this c -> c
Sep 02 2009
prev sibling parent Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
A Bothe wrote:
 What's your favorite line of D code?

I like my recent: c.resFunc = cast(void function(void*))(*cast(void***)proto.resources[origResIdx].init().ptr)[ Command.Type.ResAcquire == c.type ? 1 : 2 ]; Sure, it's 3 lines, but still one statement and if I were downs, that would *be* one line ;D -- Tomasz Stachowiak http://h3.team0xf.com/ h3/h3r3tic on #D freenode
Aug 30 2009