digitalmars.D.learn - Introspecting a package for submodules
- Anonymouse (13/13) Aug 24 2020 I have some modules, and then one `package.d` file that publicly
- Anonymouse (6/10) Aug 24 2020 `std.algorithm` makes for a bad example as it is actually empty
- Adam D. Ruppe (15/16) Aug 24 2020 Not really a way. A package doesn't quite exist in D; there is no
- Basile B. (4/9) Aug 24 2020 Wrong. Packages and modules exist in D as derived of
I have some modules, and then one `package.d` file that publicly imports them all. I have reason to access them individually however, with hopes of being able to enumerate them and introspect with `__traits(allMembers, someModule)`. Concretely, I want to express "find all module-level classes in all submodules of this package". As an analogy, I have `std.algorithm` and I want to programmatically get `std.algorithm.comparison`, `std.algorithm.iteration`, `std.algorithm.mutation`, etc -- either as symbols or as strings. `__traits(allMembers, std.algorithm)` evaluates to nothing, but replace it with `std.algorithm.searching` and it does. How do I do this? (Is there some other way?)
Aug 24 2020
On Monday, 24 August 2020 at 22:32:52 UTC, Anonymouse wrote:`__traits(allMembers, std.algorithm)` evaluates to nothing, but replace it with `std.algorithm.searching` and it does.`std.algorithm` makes for a bad example as it is actually empty save for imports. Just read it as `std.datetime` please, which has struct members.`__traits(allMembers, std.datetime)` evaluates to nothing, but replace it with `std.datetime.systime` and it does.This makes everything really difficult. Is it intentional? https://run.dlang.io/is/UAHiAo
Aug 24 2020
On Monday, 24 August 2020 at 22:32:52 UTC, Anonymouse wrote:How do I do this? (Is there some other way?)Not really a way. A package doesn't quite exist in D; there is no formal construct that is a package and has a defined list if stuff. It is just whatever modules are compiled in that happen to have the same starting bits in their name. If you made a file and put `module std.algorithm.mystuff;`, the language would treat it exactly the same way as if it was the Phobos authors did... the two files have no connection beside name, and need not even be compiled together, so no compile-time introspection could ever list it all. What some people do is have a pre-build step that scans the files and pulls the module names out ahead of time, then you can organize them by name too and sort it that way. But the compiler isn't really of any help.
Aug 24 2020
On Tuesday, 25 August 2020 at 00:09:38 UTC, Adam D. Ruppe wrote:On Monday, 24 August 2020 at 22:32:52 UTC, Anonymouse wrote:Wrong. Packages and modules exist in D as derived of ScopeDsymbol. OP just encounters a small bug. https://github.com/dlang/dmd/pull/11619How do I do this? (Is there some other way?)Not really a way. A package doesn't quite exist in D; there is no formal construct that is a package and has a defined list if stuff.
Aug 24 2020