July 19, 2012
"Petr Janda" , dans le message (digitalmars.D:172719), a écrit :
>> Array gets sorted, then doubles are removed (uniq) and then everything is converted to a string (map).
>>
>> Everything was recently introduced around 2.059.
> 
> Ok, but what is map!(). What's the point of the exclamation mark, is it a template specialization?

Yes, !(...) is template specialization.
It is the equivalent of <...> in c++.
The parentheses can be omited if only one argument is passed after the
exclamation mark.

map is a template of the std.algorithm module. http://dlang.org/phobos/std_algorithm.html#map

This kind of questions should go in digitalmars.D.learn.

-- 
Christophe
July 19, 2012
Am 19.07.2012 16:31, schrieb Petr Janda:
>> Array gets sorted, then doubles are removed (uniq) and then everything
>> is converted to a string (map).
>>
>> Everything was recently introduced around 2.059.
>
> Ok, but what is map!(). What's the point of the exclamation mark, is it
> a template specialization?


without UFCS: map!(x => to!string(x))(my_range)
Map is a template which takes a function/delegate/string at compile time, basic template usage.
July 19, 2012
"Robik" , dans le message (digitalmars.D:172718), a écrit :
> 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"]

To be more precise, `r` variable is a lazy range, equivalent to this array. r.array would be this array.


July 19, 2012
On Thursday, 19 July 2012 at 14:31:53 UTC, travert@phare.normalesup.org (Christophe Travert) wrote:
> "q66" , dans le message (digitalmars.D:172716), a écrit :
>> (so instead of calling a(b(c(d(e(f))))) you can just call a.b.c.d.e.f())
>
> rather f.e.d.c.b.a, if you omit the empty parenthesis after each letter
> (but f).

Ok, but the empty parenthesis is is important, it tells you about whether it's a an object or a function.

It's another thing I hate about Ruby is that a parenthesis enforcement is weak.
July 19, 2012
On 19-07-2012 16:36, Christophe Travert wrote:
> "Petr Janda" , dans le message (digitalmars.D:172719), a écrit :
>>> Array gets sorted, then doubles are removed (uniq) and then
>>> everything is converted to a string (map).
>>>
>>> Everything was recently introduced around 2.059.
>>
>> Ok, but what is map!(). What's the point of the exclamation mark,
>> is it a template specialization?
>
> Yes, !(...) is template specialization.
> It is the equivalent of <...> in c++.
> The parentheses can be omited if only one argument is passed after the
> exclamation mark.
>
> map is a template of the std.algorithm module.
> http://dlang.org/phobos/std_algorithm.html#map
>
> This kind of questions should go in digitalmars.D.learn.
>

No, please, template instantiation. Specialization is something completely different, and doesn't happen at the call site.

I don't mean to be overly pedantic, but I think OP has a C++ background or similar, so wrong terminology is not going to be helpful.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
July 19, 2012
"Petr Janda" , dans le message (digitalmars.D:172727), a écrit :
> On Thursday, 19 July 2012 at 14:31:53 UTC, travert@phare.normalesup.org (Christophe Travert) wrote:
>> "q66" , dans le message (digitalmars.D:172716), a écrit :
>>> (so instead of calling a(b(c(d(e(f))))) you can just call a.b.c.d.e.f())
>>
>> rather f.e.d.c.b.a, if you omit the empty parenthesis after
>> each letter
>> (but f).
> 
> Ok, but the empty parenthesis is is important, it tells you about whether it's a an object or a function.
> 
> It's another thing I hate about Ruby is that a parenthesis enforcement is weak.

property (functions that behaves like fields) don't require
empty parenthesis. This feature has been extended to all function,
leading to the current situation. Some people would like this to
disappear, and enforce strict property. To take the function object, and
not its result, take its adress.
f == f() : the result
&f : the function.

Indeed, by looking at f, you can't tell if it is a function or an object. You can never tell much when you see an isolated symbol...
July 19, 2012
Alex Rønne Petersen , dans le message (digitalmars.D:172728), a écrit :
> On 19-07-2012 16:36, Christophe Travert wrote:
>> "Petr Janda" , dans le message (digitalmars.D:172719), a écrit :
>>>> Array gets sorted, then doubles are removed (uniq) and then
>>>> everything is converted to a string (map).
>>>>
>>>> Everything was recently introduced around 2.059.
>>>
>>> Ok, but what is map!(). What's the point of the exclamation mark,
>>> is it a template specialization?
>>
>> Yes, !(...) is template specialization.
>> It is the equivalent of <...> in c++.
>> The parentheses can be omited if only one argument is passed after the
>> exclamation mark.
>>
>> map is a template of the std.algorithm module. http://dlang.org/phobos/std_algorithm.html#map
>>
>> This kind of questions should go in digitalmars.D.learn.
>>
> 
> No, please, template instantiation. Specialization is something completely different, and doesn't happen at the call site.
> 
> I don't mean to be overly pedantic, but I think OP has a C++ background or similar, so wrong terminology is not going to be helpful.

You are right, its my mistake (well, I can still send the mistake back to Petr...).
July 19, 2012
On 19-07-2012 16:21, 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.
>

No, it's just trying to make the developer's life easier.

What you see here is uniform function call syntax (UFCS), type inference, array literals, etc. These are all more or less standard features of modern statically typed languages. See ML, C#, Scala, F#, Rust, ...

And please, don't use a title like "what has gone wrong with this language?" if you're not sure how half of the features work. I don't blame you for not understanding, but dlang.org has plenty of documentation on these things (and TDPL certainly, too). Don't expect to know exactly what some piece of code from an arbitrary language does without knowing that language first.

I suspect that you have a C++ background. If this is not accurate, ignore the rest. But if it is accurate, my plea to you is: Learn other languages. C++ has next to no innovative language features (even C++11's take on lambdas is an abomination) and encourages defensive programming to the point where it's ridiculous (I mean, no default initialization of variables? In 2012?).

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
July 19, 2012
> No, please, template instantiation. Specialization is something completely different, and doesn't happen at the call site.

Sorry, my fault. I'm a non-native english speaker.

What I meant is calling function<string>(args)

I think it's called instantiation.
July 19, 2012
On 07/19/2012 04:21 PM, 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?

Then it is mapped to string representations, just as the code says.

> What type is x?

'int', if you like.

> What kind of operator is =>,

Lambda function. It is the same as (...){ return ...; }, just without the noise.

> why is x.to!string allowed template specialization should say
> x.to!(string),

Why should it say that?

> which leads me to think that there are multiple syntaxes
> for things

There always are 'multiple syntaxes for things' if writing code should
be productive and validating code for static correctness should be
decidable.

>(why I hate dynamic languages, love compiled)
>

This is unrelated to dynamic vs. compiled. (those two terms do not
contradict each other anyway.)

> On another note, (copied from wikipedia)
>
> foreach(item; set) {
> // do something to item
> }
>
> what's with the lax syntax being allowed?

s/lax/to the point/

> Shouldn't it be at least specified "auto item"?
>

Why on earth would that be the case?

> 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.

It's just syntax. Eliminating syntax noise is fine. Code should look
like what it does.