On Friday, 11 May 2012 at 20:45:53 UTC, Vidar Wahlberg wrote:
I often call functions where one of the parameters may be an
integer which i post/pre increment/decrement. However, that can
be quite risky if the parameter is defined as "lazy" as shown
above.
The value of "a" above after calling "log" depends on whether
you've compiled with "-debug" or not, this may not be very
obvious and may take some by surprise.
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.