digitalmars.D.learn - how convert the range to slice ?
- mzfhhhh (3/3) Jan 28 2015 is there any simple way to convert?
- data man (3/6) Jan 28 2015 auto arr1 = [1,2,3].map!"a*2".array;
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (3/5) Jan 28 2015 Is there any chance we could add logic to dmd+phobos that hints
- bearophile (7/9) Jan 28 2015 It's such a fundamental part of D+Phobos that newbies are forced
- Chris Williams (3/12) Jan 28 2015 Range is not castable to array. See std.array.array to generate
- bearophile (27/29) Jan 28 2015 Currently this program:
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (3/4) Jan 28 2015 Nice, that's what I'd hoped for you'd say :)
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (7/8) Feb 01 2015 Is started digging a bit...
- bearophile (5/11) Feb 02 2015 It's probably better to ask such questions on GitHub (and to open
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (3/17) Feb 02 2015 I cracked it. First proof of concept here
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (4/4) Feb 02 2015 On Monday, 2 February 2015 at 19:04:52 UTC, Nordlöw wrote:
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/6) Jun 09 2016 Synched with DMD D conversion and improved isInputRange and
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (8/12) Jan 28 2015 Something like:
is there any simple way to convert? int [] arr1 = [1,2,3].map!"a*2"; //compile error int [] arr2 = [1,2,3].filter!"a<3";//compile error
Jan 28 2015
On Wednesday, 28 January 2015 at 14:32:38 UTC, mzfhhhh wrote:is there any simple way to convert? int [] arr1 = [1,2,3].map!"a*2"; //compile error int [] arr2 = [1,2,3].filter!"a<3";//compile errorauto arr1 = [1,2,3].map!"a*2".array; auto arr2 = [1,2,3].filter!"a<3".array;
Jan 28 2015
On Wednesday, 28 January 2015 at 14:54:27 UTC, data man wrote:auto arr1 = [1,2,3].map!"a*2".array; auto arr2 = [1,2,3].filter!"a<3".array;Is there any chance we could add logic to dmd+phobos that hints user about this?
Jan 28 2015
Nordlöw:Is there any chance we could add logic to dmd+phobos that hints user about this?It's such a fundamental part of D+Phobos that newbies are forced to learn this quickly. On the other hand an informative error message could be useful... What error message do you suggest? Bye, bearophile
Jan 28 2015
On Wednesday, 28 January 2015 at 22:43:36 UTC, bearophile wrote:Nordlöw:Range is not castable to array. See std.array.array to generate an array from a Range.Is there any chance we could add logic to dmd+phobos that hints user about this?It's such a fundamental part of D+Phobos that newbies are forced to learn this quickly. On the other hand an informative error message could be useful... What error message do you suggest? Bye, bearophile
Jan 28 2015
Chris Williams:Range is not castable to array. See std.array.array to generate an array from a Range.Currently this program: void main() { import std.range; int[] a = iota(10); } Gives an error like: test.d(3,19): Error: cannot implicitly convert expression (iota(10)) of type Result to int[] For the error message to be like yours, the compiler has to recognize a Range, this could be possible because foreach() already does that. I think you can try to open a diagnostic enhancement request. In D there are already examples of hardcoded error messages targeting newbies: void main() { int x; writeln(a); printf("%d\n", x); } Gives: test.d(3,5): Error: 'writeln' is not defined, perhaps you need to import std.stdio; ? test.d(4,5): Error: 'printf' is not defined, perhaps you need to import core.stdc.stdio; ? Bye, bearophile
Jan 28 2015
On Wednesday, 28 January 2015 at 23:15:32 UTC, bearophile wrote:I think you can try to open a diagnostic enhancement request.Nice, that's what I'd hoped for you'd say :) I'll dig into it later on...
Jan 28 2015
On Wednesday, 28 January 2015 at 23:21:34 UTC, Nordlöw wrote:I'll dig into it later on...Is started digging a bit... The magic happens at line 103 in cast.c. How do I most conveniently figure out which members (functions) a type (e->type) has? I figured I could check for typical InputRange members and issue a hint about using .array if e->type has them.
Feb 01 2015
Nordlöw:Is started digging a bit... The magic happens at line 103 in cast.c. How do I most conveniently figure out which members (functions) a type (e->type) has? I figured I could check for typical InputRange members and issue a hint about using .array if e->type has them.It's probably better to ask such questions on GitHub (and to open an enhancement request in Bugzilla). Bye, bearophile
Feb 02 2015
On Monday, 2 February 2015 at 16:56:02 UTC, bearophile wrote:Nordlöw:I cracked it. First proof of concept here https://github.com/nordlow/dmd/commit/40ce0ecf34f90c4d3053c47e9286d7574f596e15Is started digging a bit... The magic happens at line 103 in cast.c. How do I most conveniently figure out which members (functions) a type (e->type) has? I figured I could check for typical InputRange members and issue a hint about using .array if e->type has them.It's probably better to ask such questions on GitHub (and to open an enhancement request in Bugzilla). Bye, bearophile
Feb 02 2015
On Monday, 2 February 2015 at 19:04:52 UTC, Nordlöw wrote: https://github.com/nordlow/dmd/commit/40ce0ecf34f90c4d3053c47e9286d7574f596e15 Made it PR at https://github.com/D-Programming-Language/dmd/pull/4371
Feb 02 2015
On Monday, 2 February 2015 at 21:04:11 UTC, Nordlöw wrote:Made it PR at https://github.com/D-Programming-Language/dmd/pull/4371Synched with DMD D conversion and improved isInputRange and message at: https://github.com/dlang/dmd/pull/4371
Jun 09 2016
On Wednesday, 28 January 2015 at 22:43:36 UTC, bearophile wrote:It's such a fundamental part of D+Phobos that newbies are forced to learn this quickly. On the other hand an informative error message could be useful... What error message do you suggest?Something like: ..., expression of type (SomeRange!T) must be converted/transformed to T[] through .array. I have no idea if DMD could figure this out by intercepting array assignment somehow. DMD must at least be aware of the Range concept throught its duck type members when generating code for foreach, right?
Jan 28 2015