repeat

spir denis.spir at gmail.com
Mon Jan 17 10:45:13 PST 2011


On 01/17/2011 07:10 PM, Andrei Alexandrescu wrote:
> I want to generalize the functionality in string's repeat and move it
> outside std.string. There is an obvious semantic clash here. If you say
> repeat("abc", 3) did you mean one string "abcabcabc" or three strings
> "abc", "abc", and "abc"?
>
> So we need distinct names for the functions. One repeats one value, the
> other repeats a range. Moreover, I'm thinking sometimes you want to
> repeat a range lazily, i.e. instead of producing "abcabc" just return a
> range that looks like it.
>
> Ideas for a good naming scheme are welcome.

Aha! For this reason precisely, the one producing "abcabcabc" was first 
called 'multiply' in Text. But then, I implemented it as '*' and '*='; 
seemed rather intuitive --what do you think? (various other operations 
are implemented as operator overloads) Could you do something similar 
for some algos where it makes sense (and does not feel forced)?

Denis
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d mailing list