digitalmars.D - Library and site D examples
- Karmello (30/30) Jan 28 2023 should automatically include most of the standard library so one
- Tejas (11/25) Jan 28 2023 You can just `import std;` if you want to play around and don't
- Karmello (3/36) Jan 29 2023 Yes, that code works, that code is not what I'm doing. They can
- Karmello (3/9) Feb 01 2023 The solution here to put the array code in to a function that
- =?UTF-8?Q?Ali_=c3=87ehreli?= (14/22) Feb 01 2023 It doesn't have to be inside a function. For example, it is used when
- Steven Schveighoffer (23/28) Feb 02 2023 This is a bug in the compiler. Change your function to not be a
should automatically include most of the standard library so one doesn't have to constantly import them just to do basic playing around with the examples. For example, I modified an example import std.array : assocArray; import std.range : enumerate; import std.conv, std.algorithm, std.math; auto aa = iota(1,20).map!(i => round(log(i))).take(10).array; writeln(to!string(aa)); and had to import the 3rd line. This gets pretty annoying when playing around with the examples. The most common libs should automatically be imported and may be dependent on the library(e.g, if its std.traits maybe import std.meta and others related). Also, this example works but in visual stupid the same code gives me an error: Error: function `X.Music.map!(Result).map` need `this` to access member `map` X.d(22): called from here: `map(iota(1, 100))` X.d(22): called from here: `take(map(iota(1, 100)), 30u)` The difference is that I'm trying to generate this sequence at compile time(it's initializing a struct member). It should be computable without issue and I'm just replacing hard coded array. Seems iota isn't being computed at compile time. struct x { static: auto a = iota(1,1000).map!(i => round(log(i))).take(30).array; }
Jan 28 2023
On Sunday, 29 January 2023 at 00:03:31 UTC, Karmello wrote:should automatically include most of the standard library so one doesn't have to constantly import them just to do basic playing around with the examples. For example, I modified an example import std.array : assocArray; import std.range : enumerate; import std.conv, std.algorithm, std.math; auto aa = iota(1,20).map!(i => round(log(i))).take(10).array; writeln(to!string(aa)); and had to import the 3rd line. This gets pretty annoying when playing around with the examples. The most common libs should automatically be imported and may be dependent on the library(e.g, if its std.traits maybe import std.meta and others related).You can just `import std;` if you want to play around and don't care much about the first compilation time. The following code also works: ```d import std; void main(){ auto aa = iota(1,20).map!(i => round(log(i))).take(10).array; writeln(to!string(aa)); } ```
Jan 28 2023
On Sunday, 29 January 2023 at 03:49:04 UTC, Tejas wrote:On Sunday, 29 January 2023 at 00:03:31 UTC, Karmello wrote:Yes, that code works, that code is not what I'm doing. They can add import std; to every line of all the examples.should automatically include most of the standard library so one doesn't have to constantly import them just to do basic playing around with the examples. For example, I modified an example import std.array : assocArray; import std.range : enumerate; import std.conv, std.algorithm, std.math; auto aa = iota(1,20).map!(i => round(log(i))).take(10).array; writeln(to!string(aa)); and had to import the 3rd line. This gets pretty annoying when playing around with the examples. The most common libs should automatically be imported and may be dependent on the library(e.g, if its std.traits maybe import std.meta and others related).You can just `import std;` if you want to play around and don't care much about the first compilation time. The following code also works: ```d import std; void main(){ auto aa = iota(1,20).map!(i => round(log(i))).take(10).array; writeln(to!string(aa)); } ```
Jan 29 2023
struct x { static: auto a = iota(1,1000).map!(i => round(log(i))).take(30).array; }The solution here to put the array code in to a function that returns it. It's excessive. Why map needs to be hidden inside a function to get it to compile is beyond me.
Feb 01 2023
On 2/1/23 13:17, Karmello wrote:It doesn't have to be inside a function. For example, it is used when computing the initial value of a module variable here: import std.range : array, iota, take; import std.algorithm : map; import std.math : log, round; auto a = iota(1,1000).map!(i => round(log(i))).take(30).array; void main() {} Statements cannot go to the module scope. Perhaps that's the limitation you see. Regarding applying "import std;" universally, it does not work for the code above because the compiler cannot choose between std.logger's log and std.math's log. Alistruct x { static: auto a = iota(1,1000).map!(i => round(log(i))).take(30).array; }The solution here to put the array code in to a function that returns it. It's excessive. Why map needs to be hidden inside a function to get it to compile is beyond me.
Feb 01 2023
On 1/28/23 7:03 PM, Karmello wrote:struct x { static: auto a = iota(1,1000).map!(i => round(log(i))).take(30).array; }This is a bug in the compiler. Change your function to not be a templated lambda, and it works: ```d struct x { static: auto a = iota(1,1000).map!((int i) => round(log(i))).take(30).array; } ``` It can be reduced to: ```d struct x { static: auto a = [1,2,3].map!(i => i); // fails auto b = [1,2,3].map!((int i) => i); // works } ``` From testing on run.dlang.io, this hasn't worked all the way back to 2.060. There is already a bug report on this: https://issues.dlang.org/show_bug.cgi?id=20077 -Steve
Feb 02 2023