the Result Type

2013-12-08 Thread seany
std.algorithm.splitter seems to return all its return values as a type "Result", without quotes, and i dont not seem to be able to cast it to string[] or int[] with cast(string[]) ( or even cast (string) - i tried that too). I tried to use a function void function(T, R)(T arr, out R output)

Re: the Result Type

2013-12-08 Thread Ali Çehreli
On 12/08/2013 12:24 AM, seany wrote: > std.algorithm.splitter seems to return all its return values as a type > "Result", without quotes, and i dont not seem to be able to cast it to > string[] or int[] with cast(string[]) ( or even cast (string) - i tried > that too). > > I tried to use a funct

Re: the Result Type

2013-12-08 Thread seany
O_O with that knowledge, would also be possible to define new types (not aliases, but new encapsulated types) representing things such as Graph, Ring, Topology, surreal number, etc? I dont find this in your book, would you consider either adding this Volodemrot types, or in case they already

Re: the Result Type

2013-12-08 Thread Marco Leise
Am Sun, 08 Dec 2013 09:24:53 +0100 schrieb "seany" : > std.algorithm.splitter seems to return all its return values as a > type "Result", without quotes, and i dont not seem to be able to > cast it to string[] or int[] with cast(string[]) ( or even cast > (string) - i tried that too). > > I t

Re: the Result Type

2013-12-08 Thread Marco Leise
Am Sun, 08 Dec 2013 09:59:55 +0100 schrieb "seany" : > O_O > > with that knowledge, would also be possible to define new types > (not aliases, but new encapsulated types) representing things > such as Graph, Ring, Topology, surreal number, etc? All these Result types are simply structs. Struct

Re: the Result Type

2013-12-08 Thread Ali Çehreli
On 12/08/2013 12:59 AM, seany wrote: > I dont find this in your book, would you consider either adding this > Volodemrot types, I think at least a short mention is in order. :) There are two reasons why they don't appear in the book (yet): 1) They are not a proper language feature, rather a ha

Re: the Result Type

2013-12-08 Thread bearophile
Ali Çehreli: When you eagerly need an actual array of the elements, call std.array.array on Result: import std.array; import std.algorithm; void main() { auto input = "hello world"; auto splittedWords = input.splitter(' ').array; Or just use the eager split() function. Bye, bearoph

Re: the Result Type

2013-12-08 Thread seany
On Sunday, 8 December 2013 at 11:02:40 UTC, Ali Çehreli wrote: (I remember Andrei's original newsgroup post about this discovery but I cannot find it at this time.) http://www.digitalmars.com/d/archives/digitalmars/D/announce/Voldemort_Types_in_D_23511.html this?

Re: the Result Type

2013-12-08 Thread Ali Çehreli
On 12/08/2013 03:41 AM, seany wrote: On Sunday, 8 December 2013 at 11:02:40 UTC, Ali Çehreli wrote: (I remember Andrei's original newsgroup post about this discovery but I cannot find it at this time.) http://www.digitalmars.com/d/archives/digitalmars/D/announce/Voldemort_Types_in_D_23511.html

Re: the Result Type

2013-12-08 Thread Philippe Sigaud
On Sun, Dec 8, 2013 at 9:59 AM, seany wrote: > O_O > > with that knowledge, would also be possible to define new types (not > aliases, but new encapsulated types) representing things such as Graph, > Ring, Topology, surreal number, etc? Other posters already answered your questions concerning ran

What is the 'Result' type even for?

2023-01-19 Thread Ruby The Roobster via Digitalmars-d-learn
prints: ["a", "b", "c", "d", "e"] Result What is the purpose of this 'Result' type? To serve as a generic range? Because, it seems to only cause problems. For example, you cannot assign or cast the result type into a range, even when

Re: What is the 'Result' type even for?

2023-01-19 Thread Ruby The Roobster via Digitalmars-d-learn
assert(c.equal(e)); typeof(c).stringof.writeln; } ``` The program prints: ["a", "b", "c", "d", "e"] Result What is the purpose of this 'Result' type? To serve as a generic range? Because, it seems to only cause problems. For exam

Re: What is the 'Result' type even for?

2023-01-19 Thread Steven Schveighoffer via Digitalmars-d-learn
    typeof(c).stringof.writeln; } ``` The program prints: ["a", "b", "c", "d", "e"] Result What is the purpose of this 'Result' type?  To serve as a generic range?  Because, it seems to only cause problems.  For example, you cann

Re: What is the 'Result' type even for?

2023-01-19 Thread H. S. Teoh via Digitalmars-d-learn
pose of this 'Result' type? To serve as a generic > range? It's a Voldemort type, representing a range that iterates over its elements lazily. > Because, it seems to only cause problems. For example, you cannot > assign or cast the result type into a range, even when the

Re: What is the 'Result' type even for?

2023-01-19 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 03:30:56 UTC, Steven Schveighoffer wrote: On 1/19/23 10:11 PM, Ruby The Roobster wrote: ... The point is to be a range over the original input, evaluated lazily. Using this building block, you can create an array, or use some other algorithm, or whatever you want.

Re: What is the 'Result' type even for?

2023-01-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 20, 2023 at 03:34:43AM +, Ruby The Roobster via Digitalmars-d-learn wrote: > On Friday, 20 January 2023 at 03:30:56 UTC, Steven Schveighoffer wrote: > > On 1/19/23 10:11 PM, Ruby The Roobster wrote: > > ... > > > > The point is to be a range over the original input, evaluated > >

Re: What is the 'Result' type even for?

2023-01-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/19/23 10:34 PM, Ruby The Roobster wrote: On Friday, 20 January 2023 at 03:30:56 UTC, Steven Schveighoffer wrote: On 1/19/23 10:11 PM, Ruby The Roobster wrote: ... The point is to be a range over the original input, evaluated lazily. Using this building block, you can create an array, or u

Re: What is the 'Result' type even for?

2023-01-19 Thread Basile B. via Digitalmars-d-learn
On Friday, 20 January 2023 at 03:11:33 UTC, Ruby The Roobster wrote: Take this example: [...] What is the purpose of this 'Result' type? To serve as a generic range? Yes this is a lazy input range. Use `.array` to yield directly as a concrete value, then you can append using `~=`. Note tha

Re: What is the 'Result' type even for?

2023-01-19 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 20 January 2023 at 03:11:33 UTC, Ruby The Roobster wrote: What is the purpose of this 'Result' type? To serve as a generic range? Because, it seems to only cause problems... No. When I first started learning this language, I thought the same thing. However, such a designm cons

Re: What is the 'Result' type even for?

2023-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 1/19/23 19:11, Ruby The Roobster wrote: > typeof(c).stringof.writeln; > The program prints: > > ["a", "b", "c", "d", "e"] > Result > > What is the purpose of this 'Result' type? Just to make sure, 'Result' is what the programmer of a Phobos algorithm chose to name a struct type. It cou

Re: What is the 'Result' type even for?

2023-01-20 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 20 January 2023 at 04:46:07 UTC, Ali Çehreli wrote: Different instantiations of templates are distinct types. For example, if I called 'alternate' with two 'long' values, both alternate!int (as instantiated by the code above) and alternate!long would have different MyResult struct ty

Re: What is the 'Result' type even for?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 03:39:48 UTC, H. S. Teoh wrote: On Fri, Jan 20, 2023 at 03:34:43AM +, Ruby The Roobster via Digitalmars-d-learn wrote: On Friday, 20 January 2023 at 03:30:56 UTC, Steven Schveighoffer wrote: > On 1/19/23 10:11 PM, Ruby The Roobster wrote: > ... > > The point i

Re: What is the 'Result' type even for?

2023-01-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 20, 2023 at 12:49:54PM +, Ruby The Roobster via Digitalmars-d-learn wrote: [...] > Thank you. I didn't know that there was such a property `.array`. It's not a property, it's a Phobos function from std.array. T -- INTEL = Only half of "intelligence".