Why callers should explicitly document storage classes

kennytm kennytm at gmail.com
Sun Aug 14 18:53:11 PDT 2011


Timon Gehr <timon.gehr at gmx.ch> wrote:
> On 08/14/2011 10:00 PM, Vladimir Panteleev wrote:
>> On Sun, 14 Aug 2011 22:48:18 +0300, Timon Gehr <timon.gehr at gmx.ch> wrote:
>> 
>>> requiring lazy before lazy arguments basically destroys the reason for
>>> lazy being in the language:
>>> 
>>> int foo(lazy 2*3);
>>> 
>>> is not better than
>>> 
>>> int foo({return 2*3});
>> 
>> What about requiring "lazy" only for non-pure delegates?
>> 
> 
> Actually I would rather require lazy arguments to be pure, so that they
> can be guaranteed to be executed at most once.

One problem: It is expected that the lazy argument can be re-evaluated. D's
`lazy` is actually call-by-name, which allowed stuff like 

----
void dotimes(int count, lazy void exp)
{
    for (int i = 0; i < count; i++)
       exp();
}
void foo()
{
    int x = 0;
    dotimes(10, writef(x++));
}
----

as documented in http://www.d-programming-language.org/lazy-evaluation.html


More information about the Digitalmars-d mailing list