Re: Working with ranges

2021-05-29 Thread Elmar via Digitalmars-d-learn
On Saturday, 29 May 2021 at 19:55:30 UTC, Elmar wrote: In many or most of the cases the use case doesn't actually require GC-allocation. Btw, I'm talking about core-level and systems software which concentrates on data transformations. When I only want to access a data structure but not

Re: Working with ranges

2021-05-29 Thread Elmar via Digitalmars-d-learn
On Wednesday, 26 May 2021 at 15:07:12 UTC, Jack wrote: On Wednesday, 26 May 2021 at 13:58:56 UTC, Elmar wrote: On Saturday, 8 December 2018 at 03:51:02 UTC, Adam D. Ruppe wrote: [...] That's amazing, this should be one thing that should appear in every tutorial just right at the start! I

Re: Working with ranges

2021-05-26 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 26 May 2021 at 13:58:56 UTC, Elmar wrote: This example will not compile: ``` auto starts = arr[0..$].stride(2); auto ends = arr[1..$].stride(2); randomNumbers[] = ends[] - starts[]; ``` Because `[]` is not defined for the Result range. Is there a standard

Re: Working with ranges

2021-05-26 Thread Ali Çehreli via Digitalmars-d-learn
On 5/26/21 8:07 AM, Jack wrote: maybe array from std.array to make that range in array of its own? Yes, something like this: import std; void main() { auto arr = 10.iota.map!(i => uniform(0, 100)); auto starts = arr[0..$].stride(2); auto ends = arr[1..$].stride(2); auto

Re: Working with ranges

2021-05-26 Thread Jack via Digitalmars-d-learn
On Wednesday, 26 May 2021 at 13:58:56 UTC, Elmar wrote: On Saturday, 8 December 2018 at 03:51:02 UTC, Adam D. Ruppe wrote: [...] That's amazing, this should be one thing that should appear in every tutorial just right at the start! I was looking hours for a way to generate an "iterator" (a

Re: Working with ranges

2021-05-26 Thread Elmar via Digitalmars-d-learn
On Saturday, 8 December 2018 at 03:51:02 UTC, Adam D. Ruppe wrote: On Saturday, 8 December 2018 at 03:48:10 UTC, Murilo wrote: Try passing `ps[]` to the function instead of plain `ps` and see what happens. How do I transform an array into a range? With the slicing operator, []. That's

Re: Working with ranges

2018-12-09 Thread Murilo via Digitalmars-d-learn
Hi guys, thank you for helping me out here, there is this facebook group for the D language, here we can help and teach each other. It is called Programming in D. Please join. https://www.facebook.com/groups/662119670846705/?ref=bookmarks

Re: Working with ranges

2018-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/7/18 11:16 PM, Adam D. Ruppe wrote: On Saturday, 8 December 2018 at 04:11:03 UTC, Murilo wrote: What is the difference between declaring "int[3] a = [1,2,3];" and declaring "int[] a = [1,2,3];"? Is the first an array and the second a range? They are both arrays, just the former one has

Re: Working with ranges

2018-12-07 Thread Murilo via Digitalmars-d-learn
On Saturday, 8 December 2018 at 04:16:25 UTC, Adam D. Ruppe wrote: On Saturday, 8 December 2018 at 04:11:03 UTC, Murilo wrote: What is the difference between declaring "int[3] a = [1,2,3];" and declaring "int[] a = [1,2,3];"? Is the first an array and the second a range? They are both

Re: Working with ranges

2018-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 8 December 2018 at 04:11:03 UTC, Murilo wrote: What is the difference between declaring "int[3] a = [1,2,3];" and declaring "int[] a = [1,2,3];"? Is the first an array and the second a range? They are both arrays, just the former one has a fixed size and the latter does not.

Re: Working with ranges

2018-12-07 Thread Murilo via Digitalmars-d-learn
On Saturday, 8 December 2018 at 03:51:02 UTC, Adam D. Ruppe wrote: On Saturday, 8 December 2018 at 03:48:10 UTC, Murilo wrote: Try passing `ps[]` to the function instead of plain `ps` and see what happens. How do I transform an array into a range? With the slicing operator, []. Thank you

Re: Working with ranges

2018-12-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 7, 2018 8:46:11 PM MST Adam D. Ruppe via Digitalmars-d- learn wrote: > On Saturday, 8 December 2018 at 03:37:56 UTC, Murilo wrote: > > Hi guys, I have created an array of strings with "string[12] ps > > string[12] isn't a range, but string[] is. > > Try passing `ps[]` to the

Re: Working with ranges

2018-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 8 December 2018 at 03:48:10 UTC, Murilo wrote: Try passing `ps[]` to the function instead of plain `ps` and see what happens. How do I transform an array into a range? With the slicing operator, [].

Re: Working with ranges

2018-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 8 December 2018 at 03:37:56 UTC, Murilo wrote: Hi guys, I have created an array of strings with "string[12] ps string[12] isn't a range, but string[] is. Try passing `ps[]` to the function instead of plain `ps` and see what happens.

Re: Working with ranges

2018-12-07 Thread Murilo via Digitalmars-d-learn
On Saturday, 8 December 2018 at 03:46:11 UTC, Adam D. Ruppe wrote: On Saturday, 8 December 2018 at 03:37:56 UTC, Murilo wrote: Hi guys, I have created an array of strings with "string[12] ps string[12] isn't a range, but string[] is. Try passing `ps[]` to the function instead of plain `ps`

Working with ranges

2018-12-07 Thread Murilo via Digitalmars-d-learn
Hi guys, I have created an array of strings with "string[12] ps = ["cat", "dog", "lion", "wolf", "coin", "chest", "money", "gold", "A", "B", "C", "D"];". I want to use the array as a range and I want to randomize it, like I want to transform that into several other ranges with the same

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 11, 2016 10:42:42 Ali Çehreli via Digitalmars-d-learn wrote: > Those interfaces already exist in Phobos: :) > >https://dlang.org/phobos/std_range_interfaces.html > > auto foo(int[] ints) { >import std.range; >if (ints.length > 10) { >return >

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread orip via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 18:09:26 UTC, ag0aep6g wrote: You've got some options: Wow, thanks everyone, great information! I think I understand my options now.

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread ag0aep6g via Digitalmars-d-learn
On 10/11/2016 09:55 AM, orip wrote: auto foo(int[] ints) { import std.range; if (ints.length > 10) { return chain(ints[0..5], ints[8..$]); } else { //return ints; // Error: mismatched function return type inference of int[] and Result return chain(ints[0..0], ints[0..$]); //

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 11, 2016 07:55:36 orip via Digitalmars-d-learn wrote: > I get "Error: mismatched function return type inference" errors > with choosing the return type for functions that work on ranges > using, e.g, std.algorithm or std.range functions, but have > different behavior based on

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread Ali Çehreli via Digitalmars-d-learn
On 10/11/2016 10:28 AM, TheFlyingFiddle wrote: On Tuesday, 11 October 2016 at 15:46:20 UTC, orip wrote: On Tuesday, 11 October 2016 at 13:06:37 UTC, pineapple wrote: Rewrite `return chain(ints[0..5], ints[8..$]);` as `return ints[0..5] ~ ints[8..$];` The `chain` function doesn't return an

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 15:46:20 UTC, orip wrote: On Tuesday, 11 October 2016 at 13:06:37 UTC, pineapple wrote: Rewrite `return chain(ints[0..5], ints[8..$]);` as `return ints[0..5] ~ ints[8..$];` The `chain` function doesn't return an array, it returns a lazily-evaluated sequence of

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread drug via Digitalmars-d-learn
11.10.2016 18:46, orip пишет: On Tuesday, 11 October 2016 at 13:06:37 UTC, pineapple wrote: Rewrite `return chain(ints[0..5], ints[8..$]);` as `return ints[0..5] ~ ints[8..$];` The `chain` function doesn't return an array, it returns a lazily-evaluated sequence of an entirely different type

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread orip via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 13:06:37 UTC, pineapple wrote: Rewrite `return chain(ints[0..5], ints[8..$]);` as `return ints[0..5] ~ ints[8..$];` The `chain` function doesn't return an array, it returns a lazily-evaluated sequence of an entirely different type from `int[]`. Of course it

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread pineapple via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 07:55:36 UTC, orip wrote: I get "Error: mismatched function return type inference" errors with choosing the return type for functions that work on ranges using, e.g, std.algorithm or std.range functions, but have different behavior based on runtime values. The

Working with ranges: mismatched function return type inference

2016-10-11 Thread orip via Digitalmars-d-learn
I get "Error: mismatched function return type inference" errors with choosing the return type for functions that work on ranges using, e.g, std.algorithm or std.range functions, but have different behavior based on runtime values. The return type is always a range with the same underlying