Function to print a diamond shape
Ali Çehreli
acehreli at yahoo.com
Thu Mar 20 15:46:52 PDT 2014
On 03/20/2014 03:03 PM, Brad Anderson wrote:
> I'm not entirely happy with it but:
I am not happy with my attempt either. :)
> void main()
> {
> import std.algorithm, std.range, std.stdio, std.conv;
>
> enum length = 5;
> auto rng =
> chain(iota(length), iota(length, -1, -1))
Ooh. I like that. That would have never occurred to me. :)
> .map!((a => " ".repeat(length-a)),
> (a => "#".repeat(a*2+1)))
> .map!(a => chain(a[0].joiner, a[1].joiner, "\n"))
> .joiner;
>
> writeln(rng);
> }
Does that compile for you? Failed for me with v2.066-devel-d0f461a:
./phobos/std/typetuple.d(550): Error: template instance F!(__lambda1)
cannot use local '__lambda1' as parameter to non-global template
AppliedReturnType(alias f)
./phobos/std/typetuple.d(556): Error: template instance
deneme.main.staticMap!(AppliedReturnType, __lambda1) error instantiating
./phobos/std/algorithm.d(404): instantiated from here:
staticMap!(AppliedReturnType, __lambda1, __lambda2)
deneme.d(161788): instantiated from here: map!(Result)
That is pointing at this line:
.map!((a => " ".repeat(length-a)),
A regression?
> Had some trouble with the result coming out as integers instead of
> something string-like.
I had the same problem at one point. I will try to understand when that
happens.
Ali
More information about the Digitalmars-d-learn
mailing list