On Thursday, 19 July 2012 at 14:21:47 UTC, Petr Janda wrote:
Hi,

I'm an occasional lurker on the D forums just to see where the language is going,but I'm a little puzzled. In another thread I found this code

auto r = [5, 3, 5, 6, 8].sort.uniq.map!(x => x.to!string);

I don't understand whats going on here. Int array is getting sorted, then Uniqued, then what? What type is x? What kind of operator is =>, why is x.to!string allowed template specialization should say x.to!(string), which leads me to think that there are multiple syntaxes for things(why I hate dynamic languages, love compiled)

On another note, (copied from wikipedia)

foreach(item; set) {
  // do something to item
}

what's with the lax syntax being allowed? Shouldn't it be at least specified "auto item"?

I'm sorry I don't mean to be a criticizer, but it seems to me that D is trying to be a dynamic-like compiled language way too hard.

(arguments) => result-expression is a lambda expression; sort of shorthand for (arguments) { return result-expression; } anonymous function. x.to!string thingy is the new UFCS stuff which basically allows you to transform any foo(x, y, z) to x.foo(y, z) (so instead of calling a(b(c(d(e(f))))) you can just call a.b.c.d.e.f())

dynamic languages are awesome, they have their pros and cons, for some things they're way better than static languages but for other things static will fit better.

Reply via email to