Feature request: lazy as a type constructor

Janice Caron caron800 at googlemail.com
Wed Sep 26 01:18:49 PDT 2007


The thing is, I say these things without having thought them through
properly, and then all the thinking happens as we're having these
discussions. What I /wanted/ was to be able to declare a function with
an unknown number of lazy arguments. My suggestion may have been
overkill. Perhaps it would suffice to define that

    void f(lazy T[]...)

shall mean an array of delegates. That would solve the problem that I
wanted solving.

But since I did put the original suggestion on the table, lets think
it through and see where it would lead. It would mean that you would
be able to declare lazy variables locally. Is this a good thing? I
really don't know. Let's see what an example would look like:

    lazy(int) n;

here, n is not really an int, it's a lazy(int) - that is, a delegate
returning an int. So when we assign it, we're not giving it a value,
we're giving it a function body, and then when we read it, we're
executing that function.

    lazy(int) n = x + 1;
    for (x=0; x<10; ++x)
    {
        writefln(n);
    }

What would this do? I think it would print the numbers 1 to 10. Do we
want to go down that road? I suspect not, as it's too big a departure
from the way we expect things to work.

On the other hand, to expect

    void f(lazy T[]...)

to mean an array of lazies, rather than a lazy array, is perhaps not
that unreasable. I think, therefore, that I must withdraw my original
request, and replace it with this, much simpler one: Please may there
be a way to declare a variadic function with (an unknown number of)
lazy arguments?



More information about the Digitalmars-d mailing list