Assigning value to a lazy parameter in a function call
Vidar Wahlberg
canidae at exent.net
Fri May 11 14:39:44 PDT 2012
On 2012-05-11 23:03, Chris Cain wrote:
> On Friday, 11 May 2012 at 20:45:53 UTC, Vidar Wahlberg wrote:
>> Perhaps the compiler should print out a warning when you're assigning
>> a value to a lazy parameter in a function call?
>
> The entire point of a lazy parameter is to not be
> calculated/processed until it's actually necessary. This is
> normal behavior for lazy. Most actual use cases for lazy would be made
> impractical if the compiler bombarded the programmer with warnings.
I'm not suggesting that the compiler should print a warning if you're
doing a calculation in the function call, I'm suggesting it should give
you a warning if you're assigning the result of the calculation to a
variable in the function call.
In other words, «log("%s", a + 1);» would give no warning, while
«log("%s", ++a);» and «log("%s", (a = a + 1));» would.
(Sorry if this is a duplicate, got an error upon sending, it appears
like the message never was sent)
More information about the Digitalmars-d-learn
mailing list