Just where has this language gone wrong?
Robik
szadows at gmail.com
Thu Jul 19 07:31:16 PDT 2012
On Thursday, 19 July 2012 at 14:21:47 UTC, Petr Janda wrote:
> Hi,
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);
Here's list what happens:
1) Array gets sorted
2) Duplicate elements gets removed (only unique stay)
3) Then it get's maped by delegate. It converts numbers into
strings.
`r` variable will be ["3", "5", "6", "8"]
> What type is x?
Type of x is inferred.
> What kind of operator is =>
Syntatic sugar for delegates.
> On another note, (copied from wikipedia)
>
> foreach(item; set) {
> // do something to item
> }
Item type is inferred from `set`, it's just syntactic sugar. Of
course you can use `auto` but you don't have to.
More information about the Digitalmars-d
mailing list