February 19, 2014
Bienlein:

> Would this compile:
>
> immutable s = ["red", "blue"].sum
>
> If not, it would be interesting to understand how that works :-)

This could work, but join() is (or should be) asymptotically more efficient:

reduce!q{a ~ b}("", ["red", "blue"])

Bye,
bearophile
February 19, 2014
On Wednesday, 19 February 2014 at 13:53:17 UTC, Philippe Sigaud wrote:
> On Wed, Feb 19, 2014 at 2:18 PM, Bienlein <jeti789@web.de> wrote:
>> I see. Unhappily, I don't have a D compiler handy. Would this compile:
>>
>> immutable s = ["red", "blue"].sum
>>
>> If not, it would be interesting to understand how that works :-)
>
> It won't work, since binary + is not defined for strings. I don't
> understand what you want, here.

Then how can you add a sum method to a parameterized type if it only works for numbers?

February 19, 2014
On Sunday, 16 February 2014 at 13:22:09 UTC, bearophile wrote:
> In the last days of beta3 D+Phobos is getting better in small but significant ways:
>
> immutable s = ["red", "blue"];
> auto js = s.join;
>
> This is very handy because you can join arrays from constant function arguments, or the result of a map that yields const items, etc.
>
> -----------------------
>
> And I am finding the optional column number in error messages very handy, my editor/IDE often jumps at the right column, saving me tiny amounts of time that adds up making the debugging nicer. The experience is just better than before.
>
> -----------------------
>
> auto r = [10, 20, 30].sum;
>
> This has replaced me tens of usages of:
> alias sum = reduce!q{a + b};
> Or:
> alias sum = curry!(reduce!q{a + b}, 0);
>
>
> But I have found problems because currently sum(int[]) returns a long, see the discussion so far:
> https://d.puremagic.com/issues/show_bug.cgi?id=12169
>
> Bye,
> bearophile

What is q{a + b} ?
February 19, 2014
On Wednesday, 19 February 2014 at 14:03:53 UTC, Gary Willoughby wrote:
> What is q{a + b} ?

http://dlang.org/lex.html#TokenString
February 19, 2014
On Wednesday, 19 February 2014 at 13:52:06 UTC, Timon Gehr wrote:
> On 02/19/2014 02:21 PM, Dicebot wrote:
>>
>>
>> 2 issues in your snippet:
>>
>> 1) need to define separator for join
>
> No, a custom separator is not mandatory.

Ah, my bad, was expecting a default parameter, not an extra
overload. See it now in docs.
February 19, 2014
On Wednesday, 19 February 2014 at 14:02:38 UTC, Bienlein wrote:
> Then how can you add a sum method to a parameterized type if it only works for numbers?

As far as I understand it will work on anything that has binary operator "+" defined.
1 2
Next ›   Last »