repeat
spir
denis.spir at gmail.com
Mon Jan 17 13:16:56 PST 2011
On 01/17/2011 09: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.
Right, I understand your point and agree (will change Text's method
accordingly when a good name is agreed upon). What about "times"?
I had to use this function rather often (else, wouldn't had bothered
with it in Text); string types I know from other languages have it
builtin as well, so it certainly is a common need (and as you see Andrei
provides it as builtin algo as well).
About arbitrary ranges, is
repeat([1,2,3], 3)
supposed to produce
[ [1,2,3] , [1,2,3] , [1,2,3] ]
?
Denis
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list