Library and site D examples
Ali Çehreli
acehreli at yahoo.com
Wed Feb 1 21:24:28 UTC 2023
On 2/1/23 13:17, Karmello wrote:
>> 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.
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.
Ali
More information about the Digitalmars-d
mailing list