is "import std;" a valid approach or a violation of the D programming language?
Paul Backus
snarwin at gmail.com
Thu May 6 22:39:03 UTC 2021
On Thursday, 6 May 2021 at 22:27:21 UTC, Steef Boerrigter wrote:
> I've been using
>
> import std;
>
> at the top of my code for a while using dmd.
>
> None of the examples in Andrei or Ali's books do this, but
> following the turtles all the way down principle they should
> also be able to go all the way up. (or no?)
>
[...]
>
> However, gdc does not compile any code using this approach:
>
> chocolate>gdc ocr.d
> ocr.d:7:8: error: module std is in file 'std.d' which
> cannot be read
> 7 | import std;
> | ^
> import path[0] =
> /usr/lib64/gcc/x86_64-slackware-linux/10.2.0/include/d
>
>
> My question is now, am I abusing an oversight in dmd when I
> import the entire phobos library, or is it a bug of gdc to
> *not* accept this approach?
Generally speaking, you cannot import an entire package in D,
only individual modules.
The reason `import std` works is that recent versions of the D
standard library include a [package module][1] for the `std`
package. It doesn't work with gdc because the standard library
version included with gdc 10.2 is not recent enough to include
the `std` package module.
[1]: https://dlang.org/spec/module.html#package-module
More information about the Digitalmars-d
mailing list