www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - cannot access frame of function

reply Alex <sascha.orlov gmail.com> writes:
Hi all,
given this code:

import std.algorithm.iteration : sum, cumulativeFold;

void main()
{
	double[5] a;
	a = 0;
	foreach(el; a) assert(el == 0);
	a[0] = 1.0;
	a[1] = 2.0;
	a[2] = 3.0;
	a[3] = 4.0;
	a[4] = 5.0;
	foreach(el; a) assert(el != 0);
	auto asum = a[].sum;
	auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum);
}

the last line does not compile.

I found
http://forum.dlang.org/post/mailman.4097.1499105927.31550.digitalmars-d-bugs puremagic.com
and
https://issues.dlang.org/show_bug.cgi?id=11886

What I do not understand, how my example differs from the fixed 
bug?
Sep 18
parent reply user1234 <user1234 12.hu> writes:
On Monday, 18 September 2017 at 14:45:25 UTC, Alex wrote:
 Hi all,
 given this code:

 import std.algorithm.iteration : sum, cumulativeFold;

 void main()
 {
 	double[5] a;
 	a = 0;
 	foreach(el; a) assert(el == 0);
 	a[0] = 1.0;
 	a[1] = 2.0;
 	a[2] = 3.0;
 	a[3] = 4.0;
 	a[4] = 5.0;
 	foreach(el; a) assert(el != 0);
 	auto asum = a[].sum;
 	auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum);
 }

 the last line does not compile.

 I found
 http://forum.dlang.org/post/mailman.4097.1499105927.31550.digitalmars-d-bugs puremagic.com
 and
 https://issues.dlang.org/show_bug.cgi?id=11886

 What I do not understand, how my example differs from the fixed 
 bug?
asum is a lazy range and the error comes from this. Let's say that if you replace asum by 1.23 then the code compiles.
Sep 18
parent reply ag0aep6g <anonymous example.com> writes:
On 09/18/2017 08:25 PM, user1234 wrote:
 On Monday, 18 September 2017 at 14:45:25 UTC, Alex wrote:
[...]
 import std.algorithm.iteration : sum, cumulativeFold;

 void main()
 {
     double[5] a;
[...]>>     auto asum = a[].sum; [...]
 asum is a lazy range and the error comes from this.
asum is not a range. It's a double.
 Let's say that if you replace  asum by 1.23 then the code compiles.
Doesn't work for me. This still fails compilation with the same error: ---- import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; auto asum = 1.23; auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum); } ----
Sep 18
next sibling parent user1234 <user1234 12.hu> writes:
On Monday, 18 September 2017 at 18:49:54 UTC, ag0aep6g wrote:
 On 09/18/2017 08:25 PM, user1234 wrote:
 On Monday, 18 September 2017 at 14:45:25 UTC, Alex wrote:
[...]
 import std.algorithm.iteration : sum, cumulativeFold;

 void main()
 {
     double[5] a;
[...]>>     auto asum = a[].sum; [...]
 asum is a lazy range and the error comes from this.
asum is not a range. It's a double.
 Let's say that if you replace  asum by 1.23 then the code 
 compiles.
Doesn't work for me. This still fails compilation with the same error: ---- import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; auto asum = 1.23; auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum); } ----
Aw right, i had put 1.23 directly in the lambda. So, OP, you can dismiss my comment.
Sep 18
prev sibling parent Alex <sascha.orlov gmail.com> writes:
On Monday, 18 September 2017 at 18:49:54 UTC, ag0aep6g wrote:
 Doesn't work for me. This still fails compilation with the same 
 error:

 ----
 import std.algorithm.iteration : sum, cumulativeFold;
 void main()
 {
     double[5] a;
     auto asum = 1.23;
     auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum);
 }
 ----
So, this is a bug, isn't it? I assume, I should file it then...
Sep 18