Feature request: lazy as a type constructor

Janice Caron caron800 at googlemail.com
Tue Sep 25 07:11:37 PDT 2007


Please may we have "lazy" as a type constructor (as well as a
parameter storage class)? Currently I can declare a lazy array of
ints, but not an array of lazy ints. That means we can't have variadic
functions with lazy variadic parameters. It would be quite useful to
be able to do:

    void f(lazy(int)[]a...)
    {
    }

The intent here is to declare that a is a variadic array of lazy ints
- that is, an array of delegates, so that when I do

    void f(lazy(int)[]a...)
    {
        foreach(d;a)
        {
            if (a == 0) return;
        }
    }

    int show(int n)
    {
        writefln(n);
        return n;
    }

    f(show(1),show(0),show(2));

we would expect show() to be called only twice (with parameters 0 and
1). show(2) won't have happened because of the laziness.

Unfortunately I can't do that right now, because lazy is a storage
class, not a type modifier. I can make the entire array lazy, but not
the array's elements.



More information about the Digitalmars-d mailing list