Re: How does laziness and UFCS interact?

2015-03-10 Thread Logan Capaldo via Digitalmars-d-learn

On Monday, 9 March 2015 at 22:15:43 UTC, Ali Çehreli wrote:
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_detailpagev=oF8K4-bieaw#t=687

Ali


Sorry, which is right? I know ifThrown is lazy, I'm curious about 
the amount of the expression that is evaluated lazily.



  a.b().c().assumeWontThrow vs.  a.b().c().assumeWontThrow
  ^--+^^-^
 |  |
 +- lazy?   +- lazy?


The video seems to say don't use lazy functions with UFCS 
because you might think the lazy part gets evaluated first, when 
it does not. Seems reasonable, although I don't know it's any 
different than assumeWontThrow(f()).


How does laziness and UFCS interact?

2015-03-09 Thread Logan Capaldo via Digitalmars-d-learn
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()?