On Tue, May 28, 2013 at 3:20 AM, bearophile <bearophileHUGS@lycos.com> wrote:
Timothee Cour:

string a="ÙÙab";
auto b1=a.map!(a=>"<"d~a~">"d).array;
writeln(b1);//["<Ù>", "<Ù>", "<a>", "<b>", "", ""]
Why are there 2 empty strings at the end? (one per Omega if you vary the
number of such symbols in the string).

The above is just weird; is that a bug?

I think it's a bug, it's shown here, I will put it in Bugzilla:

import std.stdio: writeln;
import std.algorithm: map;
import std.array: array;
void main() {
    string a = "ÙÙab";
    a.map!(a => "<"d ~ a ~ ">"d).writeln;
    a.map!(a => "<"d ~ a ~ ">"d).array.writeln;
}


The output shows that maybe it's a problem of array():

["<Ù>", "<Ù>", "<a>", "<b>"]

["<Ù>", "<Ù>", "<a>", "<b>", "", ""]



For input ranges ranges, I don't understand why the compiler can't accept
the foreach(i,ai;a) syntax:

it should behave as follows:
foreach(i , ai; a){expr}

rewritten as:
for(size_t i=0, ai=a.front; !a.empty; a.popFront;){expr}

but it doesn't compile (it only accepts foreach(ai;a){expr}

The idea must work in all cases. For opApply, built-in arrays, built-in associative arrays and for ranges. I think it causes some clashing. If you will find it causes no clashing, then it's a candidate to become an enhancement request.

Bye,
bearophile

thanks for filing 10191!

Let's dig more the indexed foreach proposal:

opApply => present with corresponding signature to foreach(i,ai;a) => use it
built-in arrays => its an randaccess iterator so already works
associative arrays => already works, compiler rewrites to key,value
ranges => if it's not an associative array, random access iterator, doesn't have opApply with corresponding signature, then use the size_t index I mentioned (existing code makes it compile error, this proposal allows it).

Where do you think it can cause clashing?