www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - String multiplication

reply bearophile <bearophileHUGS lycos.com> writes:
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
Aug 27 2011
next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I've always used array.replicate for this.

std.range.replicate seems to be scheduled for deprecation, it only
aliases itself to repeat():

/// Equivalent to $(D repeat(value, n)). Scheduled for deprecation.
Take!(Repeat!T) replicate(T)(T value, size_t n)
{
    return repeat(value, n);
}
Aug 27 2011
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Saturday, August 27, 2011 16:30:17 Andrej Mitrovic wrote:
 I've always used array.replicate for this.
 
 std.range.replicate seems to be scheduled for deprecation, it only
 aliases itself to repeat():
 
 /// Equivalent to $(D repeat(value, n)). Scheduled for deprecation.
 Take!(Repeat!T) replicate(T)(T value, size_t n)
 {
     return repeat(value, n);
 }

Yeah. The name clash is a result of the rearranging of names of std.array, std.string, std.range, etc. that Andrei did a few months back. It's annoying, but the name clashes will go away as soon as the old functions have gone through the full deprecation cycle. In the interim, you just have to fully qualify the functions. - Jonathan M Davis
Aug 27 2011