Random string samples & unicode

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Sep 11 07:48:49 PDT 2010


I think this might be a compiler bug:


import std.conv : to;

void main()
{
    string mystring;
    dchar mydchar;

    // ok, appending dchar to string
    mystring ~= mydchar;

    // error:  incompatible types for
    // ((cast(uint)mydchar) ~ (cast(uint)mydchar)): 'uint' and 'uint'
    mystring ~= mydchar ~ mydchar;
}


On Sat, Sep 11, 2010 at 3:42 PM, bearophile <bearophileHUGS at lycos.com> wrote:
>> There randomCover() doesn't work with a string, a dstrings or with a char[].
>> If later you need to process that res dchar[] with std.string you will have troubles.
>
> The problems are more widespread, this is a simple generator of terms of the "look and say" sequence (to generate a member of the sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit: http://en.wikipedia.org/wiki/Look_and_say_sequence ):
>
>
> import std.stdio, std.conv, std.algorithm;
>
> string lookAndSay(string input) {
>    string result;
>    foreach (g; group(input))
>        result ~= to!string(g._1) ~ (cast(char)g._0);
>    return result;
> }
>
> void main() {
>    string last = "1";
>    writeln(last);
>    foreach (i; 0 .. 10) {
>        last = lookAndSay(last);
>        writeln(last);
>    }
> }
>
>
> I was not able to remove that cast(char), even if I replace all strings in that program with dstrings.
> Is someone else using D2?
>
> Bye,
> bearophile
>


More information about the Digitalmars-d mailing list