Re: Assigning value to a lazy parameter in a function call

2012-05-11 Thread Chris Cain
On Friday, 11 May 2012 at 23:07:31 UTC, Vidar Wahlberg wrote: Thank you for the detailed answer. I still suspect this can fool some people, and (in my ignorance) I couldn't (and still can't, to be honest) really see when you would want to assign a variable in a lazy parameter, I would expect t

Re: Assigning value to a lazy parameter in a function call

2012-05-11 Thread Vidar Wahlberg
On 2012-05-12 00:27, Chris Cain wrote: [...] Thank you for the detailed answer. I still suspect this can fool some people, and (in my ignorance) I couldn't (and still can't, to be honest) really see when you would want to assign a variable in a lazy parameter, I would expect that to be far m

Re: Assigning value to a lazy parameter in a function call

2012-05-11 Thread Chris Cain
On Friday, 11 May 2012 at 21:39:57 UTC, Vidar Wahlberg wrote: 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 functi

Re: Assigning value to a lazy parameter in a function call

2012-05-11 Thread Jonathan M Davis
On Friday, May 11, 2012 23:39:44 Vidar Wahlberg wrote: > 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? > > > >

Re: Assigning value to a lazy parameter in a function call

2012-05-11 Thread Vidar Wahlberg
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 unti

Re: Assigning value to a lazy parameter in a function call

2012-05-11 Thread Chris Cain
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 "l

Assigning value to a lazy parameter in a function call

2012-05-11 Thread Vidar Wahlberg
Wasn't easy to find a short good description of the issue in the subject, but here's some code to illustrate my "concern": --- import std.stdio; void log(T...)(lazy string message, lazy T t) { debug writefln(message, t); } void main() { int a = 42; writefln("The meaning of