How does laziness and UFCS interact?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 9 15:15:43 PDT 2015


On 03/09/2015 03:03 PM, Logan Capaldo wrote:
> I just became aware of
> http://dlang.org/phobos/std_exception.html#.ifThrown . It's neat, but it
> seems non-obvious to me how lazy + UFCS should work in general.
>
> consider
>
>
> void lazily(T)(lazy T expression)
> {
>     expression();
> }
>
> It's clear when saying lazily(a.b().c()); that the whole of "a.b().c()"
> is going to be evaluated lazily. With UFCS though, I'm more unsure:
>
> is a.b().c().lazily() -> lazily(a.b().c()) or is it more akin to
>
> auto tmp = a.b();
> lazily(tmp.c());
>
> If the later is it possible to force the former while still using UFCS,
> ie is (a.b().c()).lazily() different than a.b().c().lazily()?
>
>

You are right. I had the same observation at minute 11:27 below, where I 
warn against UFCS with assumeWontThrow:

 
http://www.youtube.com/watch?feature=player_detailpage&v=oF8K4-bieaw#t=687

Ali



More information about the Digitalmars-d-learn mailing list