On Sun, 20 Feb 2011 14:51:10 -0500, bearophile <[email protected]>
wrote:
Jacob Carlborg:
Every time I try to use D2 it's just a PITA to use. I've used D1 and
Tango for
several years and had no problem with that.
I use this thread to ask regarding one specific little problem I have
with strings. I want to generate a random string of AB using the array,
map, etc, this looks like a possible implementation (in std.random there
is no choice() function yet):
import std.stdio, std.random, std.string, std.algorithm, std.range;
void main() {
auto m = map!((i){ return "AB"[uniform(0,2)]; })(iota(10));
string s = join(array(m));
writeln(s);
}
It gives this error:
...\dmd\src\phobos\std\array.d(62): Error: result[i] isn't mutable
test.d(5): Error: template instance
std.array.array!(Map!(__dgliteral1,Iota!(int,uint))) error instantiating
What's the right way to write it in D?
The same code in Python2.x:
from random import choice
s = "".join(choice("AB") for _ in xrange(10))
print s
Just a blind guess, I have not tested, but maybe it's because the compiler
is using const(char) as the return type for your delegate literal since
you never specify one?
-Steve