digitalmars.D.learn - They are not the same
- bearophile (19/19) Apr 04 2014 Can you spot the difference between foo1 and foo2?
- Meta (4/23) Apr 04 2014 When I put a println inside both functions, they both print out
- Meta (2/5) Apr 04 2014 No, sorry, I was mistaken about what was going on.
- John Colvin (5/24) Apr 05 2014 Pity...
- bearophile (5/8) Apr 05 2014 Was this discussed in the forum? Do you think you can ask for an
- Timon Gehr (4/11) Apr 05 2014 It's a plain bug. In fact, you have commented on it:
- bearophile (5/7) Apr 05 2014 That issue is significant.
- Artur Skawina (5/22) Apr 05 2014 You're asking for bypassing immutability there (The first 'bar'.
- Timon Gehr (4/26) Apr 05 2014 The issue asks for delegates to be typed properly, unless I
- Kagamin (3/5) Apr 09 2014 Isn't the issue in pure nested functions treated as strongly
- Timon Gehr (11/16) Apr 09 2014 The issue is that pure nested functions and delegate literals are not
- Kagamin (3/3) Apr 10 2014 Pure functions are allowed to access mutable state without const
Can you spot the difference between foo1 and foo2? import std.algorithm: map; import std.range: iota; void foo1(in int[] a, in int[] b) pure { int[] r; foreach (immutable i; 0 .. a.length) r ~= (i % 2) ? a[i] : b[i]; } void foo2(in int[] a, in int[] b) pure { int[] r; foreach (x; iota(a.length) .map!(i => (i % 2) ? a[i] : b[i])) r ~= x; } void main() {} Sometimes variants of this problem hit me. I don't even know if this simple problem has a name. Is it impossible to solve? Bye, bearophile
Apr 04 2014
On Saturday, 5 April 2014 at 01:28:06 UTC, bearophile wrote:Can you spot the difference between foo1 and foo2? import std.algorithm: map; import std.range: iota; void foo1(in int[] a, in int[] b) pure { int[] r; foreach (immutable i; 0 .. a.length) r ~= (i % 2) ? a[i] : b[i]; } void foo2(in int[] a, in int[] b) pure { int[] r; foreach (x; iota(a.length) .map!(i => (i % 2) ? a[i] : b[i])) r ~= x; } void main() {} Sometimes variants of this problem hit me. I don't even know if this simple problem has a name. Is it impossible to solve? Bye, bearophileWhen I put a println inside both functions, they both print out [2, 1, 0]. Shouldn't the first print [0, 1, 2] while the second prints [2, 1, 0]?
Apr 04 2014
On Saturday, 5 April 2014 at 01:57:59 UTC, Meta wrote:When I put a println inside both functions, they both print out [2, 1, 0]. Shouldn't the first print [0, 1, 2] while the second prints [2, 1, 0]?No, sorry, I was mistaken about what was going on.
Apr 04 2014
On Saturday, 5 April 2014 at 01:28:06 UTC, bearophile wrote:Can you spot the difference between foo1 and foo2? import std.algorithm: map; import std.range: iota; void foo1(in int[] a, in int[] b) pure { int[] r; foreach (immutable i; 0 .. a.length) r ~= (i % 2) ? a[i] : b[i]; } void foo2(in int[] a, in int[] b) pure { int[] r; foreach (x; iota(a.length) .map!(i => (i % 2) ? a[i] : b[i])) r ~= x; } void main() {} Sometimes variants of this problem hit me. I don't even know if this simple problem has a name. Is it impossible to solve? Bye, bearophilePity... I think there's an argument that this should work, on the grounds that the context pointer is just another argument and therefore the lambda can be weakly pure.
Apr 05 2014
John Colvin:I think there's an argument that this should work, on the grounds that the context pointer is just another argument and therefore the lambda can be weakly pure.Was this discussed in the forum? Do you think you can ask for an enhancement in Bugzilla? Bye, bearophile
Apr 05 2014
On 04/05/2014 11:53 AM, bearophile wrote:John Colvin:I've been bringing this up time and time again, but it is usually ignored.I think there's an argument that this should work, on the grounds that the context pointer is just another argument and therefore the lambda can be weakly pure.Was this discussed in the forum?Do you think you can ask for an enhancement in Bugzilla? ...It's a plain bug. In fact, you have commented on it: https://d.puremagic.com/issues/show_bug.cgi?id=9148
Apr 05 2014
Timon Gehr:It's a plain bug. In fact, you have commented on it: https://d.puremagic.com/issues/show_bug.cgi?id=9148That issue is significant. Thank you Timon. Apparently my memory is not very good :-) Bye, bearophile
Apr 05 2014
On 04/05/14 21:51, Timon Gehr wrote:On 04/05/2014 11:53 AM, bearophile wrote:You're asking for bypassing immutability there (The first 'bar'. That second 'bar' does not make sense w/o properly typed delegates; the second 'foo' should indeed work). arturJohn Colvin:I've been bringing this up time and time again, but it is usually ignored.I think there's an argument that this should work, on the grounds that the context pointer is just another argument and therefore the lambda can be weakly pure.Was this discussed in the forum?Do you think you can ask for an enhancement in Bugzilla? ...It's a plain bug. In fact, you have commented on it: https://d.puremagic.com/issues/show_bug.cgi?id=9148
Apr 05 2014
On 04/05/2014 10:33 PM, Artur Skawina wrote:On 04/05/14 21:51, Timon Gehr wrote:Good point, presumably this was a copy-and-paste error.On 04/05/2014 11:53 AM, bearophile wrote:You're asking for bypassing immutability there (The first 'bar'.John Colvin:I've been bringing this up time and time again, but it is usually ignored.I think there's an argument that this should work, on the grounds that the context pointer is just another argument and therefore the lambda can be weakly pure.Was this discussed in the forum?Do you think you can ask for an enhancement in Bugzilla? ...It's a plain bug. In fact, you have commented on it: https://d.puremagic.com/issues/show_bug.cgi?id=9148That second 'bar' does not make sense w/o properly typed delegates;The issue asks for delegates to be typed properly, unless I misunderstand what 'properly' means here.the second 'foo' should indeed work). artur
Apr 05 2014
On Saturday, 5 April 2014 at 21:33:30 UTC, Timon Gehr wrote:The issue asks for delegates to be typed properly, unless I misunderstand what 'properly' means here.Isn't the issue in pure nested functions treated as strongly pure? What does it have to do with delegates?
Apr 09 2014
On 04/09/2014 07:27 PM, Kagamin wrote:On Saturday, 5 April 2014 at 21:33:30 UTC, Timon Gehr wrote:The issue is that pure nested functions and delegate literals are not allowed mutable access to data reachable using context pointers. However, this may also be exactly what is wanted in certain circumstances. 'Delegates are typed properly', I interpreted as meaning for one thing (besides fixing the unsoundness issues) that the 'immutable'/'const' qualifiers can be used on nested functions/delegate literals, which then restores the current behaviour in the case of immutable (i.e. only immutable state can be accessed through context pointers thus annotated.), and would prevent updates to data in the context in the case of const.The issue asks for delegates to be typed properly, unless I misunderstand what 'properly' means here.Isn't the issue in pure nested functions treated as strongly pure? What does it have to do with delegates?
Apr 09 2014
Pure functions are allowed to access mutable state without const qualifier. I don't understand, why you want the qualifier and how it would help with consistent implementation of purity.
Apr 10 2014