Re: The lifetime of reduce's internal seed

2014-04-26 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 26 April 2014 at 06:24:26 UTC, Ali Çehreli wrote: On 04/22/2014 11:45 AM, monarch_dodra wrote: > Reduce returns "the seed". It's actually doing something more like this: > > int[1] foo() > { > int[1] sum > sum = sum[]; //The lambda operates, and the > //r

Re: The lifetime of reduce's internal seed

2014-04-25 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2014 11:45 AM, monarch_dodra wrote: > Reduce returns "the seed". It's actually doing something more like this: > > int[1] foo() > { > int[1] sum > sum = sum[]; //The lambda operates, and the > //result is assigned back to the seed. > return sum; //Returns

Re: The lifetime of reduce's internal seed

2014-04-23 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 18:49:41 UTC, Steven Schveighoffer wrote: On Tue, 22 Apr 2014 14:47:19 -0400, monarch_dodra wrote: In this case no, but; // int[1] foo(); int[] a = foo(); // *is* slicing an rvalue, and it *does* compile. I don't think there needs to be escape analysis to

Re: The lifetime of reduce's internal seed

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 18:17:58 UTC, Ali Çehreli wrote: On 04/22/2014 11:03 AM, monarch_dodra wrote: > The "int[] reduce...", however, I think is a outright language issue. > Implicilty calling opSlice on a static array is one thing, but doing it > on an rvalue is an outright aberration. Th

Re: The lifetime of reduce's internal seed

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 18:34:47 UTC, Steven Schveighoffer wrote: On Tue, 22 Apr 2014 14:17:57 -0400, Ali Çehreli wrote: I don't think there is slicing an rvalue though. (?) reduce() is taking a copy of the seed and then returning a slice to it because the user slices it in their lambda

Re: The lifetime of reduce's internal seed

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 14:47:19 -0400, monarch_dodra wrote: In this case no, but; // int[1] foo(); int[] a = foo(); // *is* slicing an rvalue, and it *does* compile. I don't think there needs to be escape analysis to catch this. Oh yeah, that's bad. -Steve

Re: The lifetime of reduce's internal seed

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 14:17:57 -0400, Ali Çehreli wrote: I don't think there is slicing an rvalue though. (?) reduce() is taking a copy of the seed and then returning a slice to it because the user slices it in their lambda. It effectively does the following, which unfortunately compiles:

Re: The lifetime of reduce's internal seed

2014-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2014 11:03 AM, monarch_dodra wrote: > On Tuesday, 22 April 2014 at 17:31:22 UTC, Ali Çehreli wrote: >> I opened the following bug before reading reduce's documentation >> carefully: >> >> https://issues.dlang.org/show_bug.cgi?id=12610 >> >> import std.stdio; >> import std.algorithm; >>

Re: The lifetime of reduce's internal seed

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 17:31:22 UTC, Ali Çehreli wrote: I opened the following bug before reading reduce's documentation carefully: https://issues.dlang.org/show_bug.cgi?id=12610 import std.stdio; import std.algorithm; void main() { int[] arr = [ 0 ]; int[1] seed; int[] r

The lifetime of reduce's internal seed

2014-04-22 Thread Ali Çehreli via Digitalmars-d-learn
I opened the following bug before reading reduce's documentation carefully: https://issues.dlang.org/show_bug.cgi?id=12610 import std.stdio; import std.algorithm; void main() { int[] arr = [ 0 ]; int[1] seed; int[] result = reduce!((sum, _) => sum[])(seed, arr); writefln("%s