Re: inout and function/delegate parameters

2012-03-09 Thread Steven Schveighoffer
On Thu, 08 Mar 2012 17:43:34 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 08/03/2012 19:38, Steven Schveighoffer wrote: snip Yes, I couldn't really find that. It does specifically say casting away const and then modifying is invalid, but it does not say anything about if you know

Re: inout and function/delegate parameters

2012-03-09 Thread Stewart Gordon
On 19/02/2012 14:27, Stewart Gordon wrote: snip int opApply(int delegate(ref inout(T)) dg) inout; But then I realised a potential ambiguity: (a) the constancy is passed through to the delegate (b) the delegate has an inout parameter in its own right snip Thinking about it, if we go with (a),

Re: inout and function/delegate parameters

2012-03-09 Thread Steven Schveighoffer
On Fri, 09 Mar 2012 19:44:20 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 19/02/2012 14:27, Stewart Gordon wrote: snip int opApply(int delegate(ref inout(T)) dg) inout; But then I realised a potential ambiguity: (a) the constancy is passed through to the delegate (b) the delegate has

Re: inout and function/delegate parameters

2012-03-08 Thread Steven Schveighoffer
On Wed, 07 Mar 2012 19:06:14 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/07/2012 11:37 PM, Stewart Gordon wrote: On 07/03/2012 15:41, Steven Schveighoffer wrote: snip In fact, I think this is valid D code: int i; const int *pi = i; int *p = cast()pi; *p = 5; // legal because I know this

Re: inout and function/delegate parameters

2012-03-08 Thread Timon Gehr
On 03/08/2012 12:37 PM, Steven Schveighoffer wrote: On Wed, 07 Mar 2012 19:06:14 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/07/2012 11:37 PM, Stewart Gordon wrote: On 07/03/2012 15:41, Steven Schveighoffer wrote: snip In fact, I think this is valid D code: int i; const int *pi = i;

Re: inout and function/delegate parameters

2012-03-08 Thread Steven Schveighoffer
On Thu, 08 Mar 2012 13:17:15 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/08/2012 12:37 PM, Steven Schveighoffer wrote: On Wed, 07 Mar 2012 19:06:14 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/07/2012 11:37 PM, Stewart Gordon wrote: On 07/03/2012 15:41, Steven Schveighoffer

Re: inout and function/delegate parameters

2012-03-08 Thread Stewart Gordon
On 08/03/2012 19:38, Steven Schveighoffer wrote: snip Yes, I couldn't really find that. It does specifically say casting away const and then modifying is invalid, but it does not say anything about if you know the underlying data is mutable. But again, this is the point I was trying to make,

Re: inout and function/delegate parameters

2012-03-07 Thread Steven Schveighoffer
On Tue, 06 Mar 2012 05:11:34 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/06/2012 12:27 AM, Steven Schveighoffer wrote: ... There are two parts to inout, one is that it can be one function called 3 different ways, the other is that you know it's constant during function execution. Some

Re: inout and function/delegate parameters

2012-03-07 Thread Stewart Gordon
On 07/03/2012 15:41, Steven Schveighoffer wrote: snip In fact, I think this is valid D code: int i; const int *pi = i; int *p = cast()pi; *p = 5; // legal because I know this points at i, and i is really mutable cast() is an abomination. I'm not sure OTTOMH whether it's a bug that it works.

Re: inout and function/delegate parameters

2012-03-07 Thread Steven Schveighoffer
On Wed, 07 Mar 2012 17:37:53 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 07/03/2012 15:41, Steven Schveighoffer wrote: snip In fact, I think this is valid D code: int i; const int *pi = i; int *p = cast()pi; *p = 5; // legal because I know this points at i, and i is really mutable

Re: inout and function/delegate parameters

2012-03-07 Thread Stewart Gordon
On 07/03/2012 22:48, Steven Schveighoffer wrote: On Wed, 07 Mar 2012 17:37:53 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: snip cast() is an abomination. I'm not sure OTTOMH whether it's a bug that it works. Sorry, it's just easier than typing cast(int*). Which is another abomination.

Re: inout and function/delegate parameters

2012-03-07 Thread Steven Schveighoffer
On Wed, 07 Mar 2012 18:01:10 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 07/03/2012 22:48, Steven Schveighoffer wrote: On Wed, 07 Mar 2012 17:37:53 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: snip cast() is an abomination. I'm not sure OTTOMH whether it's a bug that it

Re: inout and function/delegate parameters

2012-03-07 Thread Timon Gehr
On 03/07/2012 11:37 PM, Stewart Gordon wrote: On 07/03/2012 15:41, Steven Schveighoffer wrote: snip In fact, I think this is valid D code: int i; const int *pi = i; int *p = cast()pi; *p = 5; // legal because I know this points at i, and i is really mutable cast() is an abomination. I'm not

Re: inout and function/delegate parameters

2012-03-07 Thread Timon Gehr
On 03/07/2012 04:41 PM, Steven Schveighoffer wrote: On Tue, 06 Mar 2012 05:11:34 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/06/2012 12:27 AM, Steven Schveighoffer wrote: ... There are two parts to inout, one is that it can be one function called 3 different ways, the other is that you

Re: inout and function/delegate parameters

2012-03-06 Thread Timon Gehr
On 03/06/2012 12:27 AM, Steven Schveighoffer wrote: ... There are two parts to inout, one is that it can be one function called 3 different ways, the other is that you know it's constant during function execution. Some people like that second part, even if it doesn't fully guarantee everything.

Re: inout and function/delegate parameters

2012-03-05 Thread Steven Schveighoffer
On Sat, 25 Feb 2012 09:02:47 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 02/24/2012 05:26 PM, Steven Schveighoffer wrote: On Sun, 19 Feb 2012 09:27:42 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: At the moment, if a function has an inout parameter, it must have an inout return type.

Re: inout and function/delegate parameters

2012-03-05 Thread Stewart Gordon
On 05/03/2012 13:49, Steven Schveighoffer wrote: On Sat, 25 Feb 2012 09:02:47 -0500, Timon Gehr timon.g...@gmx.ch wrote: snip inout means 'some qualifier but we don't know which one'. The call site on the other hand knows which qualifier it is. If the call is made to work there is no 'making

Re: inout and function/delegate parameters

2012-03-05 Thread Steven Schveighoffer
On Mon, 05 Mar 2012 11:17:41 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 05/03/2012 13:49, Steven Schveighoffer wrote: On Sat, 25 Feb 2012 09:02:47 -0500, Timon Gehr timon.g...@gmx.ch wrote: snip inout means 'some qualifier but we don't know which one'. The call site on the other

Re: inout and function/delegate parameters

2012-03-05 Thread Timon Gehr
On 03/05/2012 11:31 PM, Steven Schveighoffer wrote: On Mon, 05 Mar 2012 11:17:41 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 05/03/2012 13:49, Steven Schveighoffer wrote: On Sat, 25 Feb 2012 09:02:47 -0500, Timon Gehr timon.g...@gmx.ch wrote: snip inout means 'some qualifier but we

Re: inout and function/delegate parameters

2012-03-05 Thread Steven Schveighoffer
On Mon, 05 Mar 2012 18:01:34 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/05/2012 11:31 PM, Steven Schveighoffer wrote: On Mon, 05 Mar 2012 11:17:41 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 05/03/2012 13:49, Steven Schveighoffer wrote: On Sat, 25 Feb 2012 09:02:47 -0500,

Re: inout and function/delegate parameters

2012-03-05 Thread Stewart Gordon
On 05/03/2012 22:31, Steven Schveighoffer wrote: On Mon, 05 Mar 2012 11:17:41 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 05/03/2012 13:49, Steven Schveighoffer wrote: snip It's currently transitive, and this would break transitivity. If we want to look at fundamentally redefining

Re: inout and function/delegate parameters

2012-03-05 Thread Steven Schveighoffer
On Mon, 05 Mar 2012 20:34:09 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 05/03/2012 22:31, Steven Schveighoffer wrote: On Mon, 05 Mar 2012 11:17:41 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 05/03/2012 13:49, Steven Schveighoffer wrote: snip It's currently transitive,

Re: inout and function/delegate parameters

2012-02-25 Thread Timon Gehr
On 02/24/2012 05:26 PM, Steven Schveighoffer wrote: On Sun, 19 Feb 2012 09:27:42 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: At the moment, if a function has an inout parameter, it must have an inout return type. But this prevents doing stuff like void test(ref inout(int)[] x,

Re: inout and function/delegate parameters

2012-02-24 Thread Steven Schveighoffer
On Sun, 19 Feb 2012 09:27:42 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: At the moment, if a function has an inout parameter, it must have an inout return type. But this prevents doing stuff like void test(ref inout(int)[] x, inout(int)[] y) { x = y; } This is a

inout and function/delegate parameters

2012-02-19 Thread Stewart Gordon
At the moment, if a function has an inout parameter, it must have an inout return type. But this prevents doing stuff like void test(ref inout(int)[] x, inout(int)[] y) { x = y; } or passing the constancy through to a delegate instead of a return value. A typical use case of

Re: inout and function/delegate parameters

2012-02-19 Thread Timon Gehr
On 02/19/2012 03:27 PM, Stewart Gordon wrote: At the moment, if a function has an inout parameter, it must have an inout return type. But this prevents doing stuff like void test(ref inout(int)[] x, inout(int)[] y) { x = y; } or passing the constancy through to a delegate instead of a return

Re: inout and function/delegate parameters

2012-02-19 Thread Stewart Gordon
On 19/02/2012 15:31, Timon Gehr wrote: snip excessive quote snip a) int opApply(inout int delegate(ref inout(T)) dg) inout; b) int opApply(constancy K)(int delegate(constancy L)(ref L(T)) dg) K; ??? Actually affecting the constancy of the delegate itself is not an useful operation anyway,

Re: inout and function/delegate parameters

2012-02-19 Thread Timon Gehr
On 02/19/2012 06:09 PM, Stewart Gordon wrote: On 19/02/2012 15:31, Timon Gehr wrote: snip excessive quote snip a) int opApply(inout int delegate(ref inout(T)) dg) inout; b) int opApply(constancy K)(int delegate(constancy L)(ref L(T)) dg) K; ??? oops... a) int opApply(inout int delegate(ref

Re: inout and function/delegate parameters

2012-02-19 Thread kenji hara
I think the 'scope' keyword may resolve issue. Attributes of lazy parameter in template function belong to caller side. int foo()(lazy int value) @safe pure /*nothrow*/ { return value(); } void main() { int n = foo(10); // evaluating lazy parameter never break safety and purity of foo.

Re: inout and function/delegate parameters

2012-02-19 Thread Timon Gehr
On 02/19/2012 11:27 PM, kenji hara wrote: I think the 'scope' keyword may resolve issue. Attributes of lazy parameter in template function belong to caller side. int foo()(lazy int value) @safe pure /*nothrow*/ { return value(); } void main() { int n = foo(10); // evaluating lazy