repeat
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Jan 17 13:00:33 PST 2011
On 1/17/11 2:15 PM, Jonathan M Davis wrote:
> On Monday, January 17, 2011 10:59:16 spir wrote:
>> On 01/17/2011 07:53 PM, Adam Ruppe wrote:
>>> It seems to me that you actually want two separate functions:
>>>
>>> repeat("abc", 3) => ["abc", "abc", "abc"]
>>>
>>> join(repeat("abc", 3)) => "abcabcabc"
>>
>> Would rather see:
>>
>> repeat("abc", 3) => ["abc", "abc", "abc"]
>> "abc" * 3 => "abcabcabc"
>
> Considering that D add the ~ operator for concatenation because + was too
> ambiguous (e.g. what should "2" + "3" do?), there's no way that overloading *
> for a function in std.algorithm is going to fly. And since we're dealing with
> arbitrary range types - not just strings - it definitely isn't going to work. Not
> to mention, using an operator like that implies that it'sa basic and important
> operation. However, I'm not sure that I've ever had to use such an operation in
> my entire life. It needs a normal function, not an overloaded operator.
I just moved join from string to array, defined multiply to copy a range
multiple times into an array, and changed replicate to repeat:
http://www.dsource.org/projects/phobos/changeset/2343
http://d-programming-language.org/cutting-edge/phobos/std_array.html
http://d-programming-language.org/cutting-edge/phobos/std_string.html
Andrei
More information about the Digitalmars-d
mailing list