www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How much to do

reply bearophile <bearophileHUGS lycos.com> writes:
Recently lot of work has being done about "inout", and I think it is now usable
in D2.

So this has made me ask how much needs to be done (in D language and/or Phobos)
to allow the correct compilation of exactly this useless demo program (I think
it is correct):


import std.algorithm, std.range, std.array;
auto foo(in int[] data) pure {
    immutable int n = count!q{ a % 2 == 1 }(data);
    return map!q{ a * 2 }([n, n+1, n+2]);
}
void main() {
    auto a = array(iota(10));
    assert(equal(foo(a), [10, 12, 14]));
}


Currently count can't digest a const array and that map isn't pure. It runs if
you remove "in" and "pure".

Once this program compiles I think std.algorithm becomes significantly more
usable.

Bye,
bearophile
Oct 06 2011
parent reply kennytm <kennytm gmail.com> writes:
bearophile <bearophileHUGS lycos.com> wrote:
 Recently lot of work has being done about "inout", and I think it is now
usable in D2.
 
 So this has made me ask how much needs to be done (in D language and/or
 Phobos) to allow the correct compilation of exactly this useless demo
 program (I think it is correct):
 
 
 import std.algorithm, std.range, std.array;
 auto foo(in int[] data) pure {
     immutable int n = count!q{ a % 2 == 1 }(data);
     return map!q{ a * 2 }([n, n+1, n+2]);
 }
 void main() {
     auto a = array(iota(10));
     assert(equal(foo(a), [10, 12, 14]));
 }
 
 
 Currently count can't digest a const array and that map isn't pure. It
 runs if you remove "in" and "pure".
 
 Once this program compiles I think std.algorithm becomes significantly more
usable.
 
 Bye,
 bearophile

Allow a template argument to treat a const(T[]) as a const(T)[] is a different and a known problem IIRC.
Oct 06 2011
parent bearophile <bearophileHUGS lycos.com> writes:
kennytm:

 Allow a template argument to treat a const(T[]) as a const(T)[] is a
 different and a known problem IIRC.

I don't fully understand the meaning of your answer, but I didn't want to imply that those two problems are new or unknown. Bye, bearophile
Oct 07 2011