String multiplication

bearophile bearophileHUGS at lycos.com
Sat Aug 27 06:59:44 PDT 2011


In Python you write:

s1 = "ax" * 10

It's a common operation, so it's right to give such * operator to Python strings.


In D you used to write (I'd like it to be called "mul" instead of "repeat"):

import std.stdio, std.string, std.array, std.range;
void main() {
    auto s1 = repeat("ax", 10);
}


Now that gives:

Notice: As of Phobos 2.055, std.string.repeat has been deprecated It will be removed in February 2012. Please use std.array.replicate instead.
test.d(3): Error: std.range.repeat!(string).repeat at C:\dmd2\src\phobos\std\range.d(2662) conflicts with std.string.repeat!(string).repeat at C:\dmd2\src\phobos\std\string.d(1367)


If I follow that suggestion, and write this:


import std.stdio, std.string, std.array, std.range;
void main() {
    auto s1 = replicate("ax", 10);
}


Now it gives (2.055head):

test.d(3): Error: std.range.replicate!(string).replicate at ...\src\phobos\std\range.d(2668) conflicts with std.array.replicate!(string).replicate at ...\src\phobos\std\array.d(979)

Is this expected and good enough?

Is something here worth some kind of enhancement request? What kind of request?

Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list