digitalmars.D.learn - Dynamic length string array at compile time?
- Dany12L (2/2) Jun 05 2023 Hi, I'd be interested to know if it's possible to have a dynamic
- Steven Schveighoffer (5/9) Jun 06 2023 Sure. Just do it. Probably the reason nobody answered the question yet
- Dany12L (6/17) Jun 06 2023 My concern would be to create an immutable array (or other
- Steven Schveighoffer (11/26) Jun 06 2023 OK, so you want to affect the same static variable from multiple places?...
- Mark Fisher (7/14) Jun 15 2023 Hi,
- Steven Schveighoffer (10/15) Jun 15 2023 Well, as long as it's not *compile time*, but runtime, you can
Hi, I'd be interested to know if it's possible to have a dynamic length array containing strings generated at compile time.
Jun 05 2023
On 6/5/23 11:45 AM, Dany12L wrote:Hi, I'd be interested to know if it's possible to have a dynamic length array containing strings generated at compile time.Sure. Just do it. Probably the reason nobody answered the question yet is that it trivially works if you try it :) Unless you did try it and it didn't work? In that case, post your code, I'm sure we can fix it. -Steve
Jun 06 2023
On Tuesday, 6 June 2023 at 14:26:01 UTC, Steven Schveighoffer wrote:On 6/5/23 11:45 AM, Dany12L wrote:My concern would be to create an immutable array (or other "equivalent") of strings by adding elements to the array at compile time from different modules. I would like to know if it is possible to do something similarHi, I'd be interested to know if it's possible to have a dynamic length array containing strings generated at compile time.Sure. Just do it. Probably the reason nobody answered the question yet is that it trivially works if you try it :) Unless you did try it and it didn't work? In that case, post your code, I'm sure we can fix it. -Steve
Jun 06 2023
On 6/6/23 4:38 PM, Dany12L wrote:On Tuesday, 6 June 2023 at 14:26:01 UTC, Steven Schveighoffer wrote:OK, so you want to affect the same static variable from multiple places? No, that can't happen that way. You can do it in a functional programming fashion, but there can only be one initialization, you can't edit the thing afterwards. So for instance, you can do: ```d immutable string[] strs = mod1.makeStrings() ~ mod2.makeStrings() ~ ...; ``` In a centralized place. -SteveOn 6/5/23 11:45 AM, Dany12L wrote:My concern would be to create an immutable array (or other "equivalent") of strings by adding elements to the array at compile time from different modules.Hi, I'd be interested to know if it's possible to have a dynamic length array containing strings generated at compile time.Sure. Just do it. Probably the reason nobody answered the question yet is that it trivially works if you try it :) Unless you did try it and it didn't work? In that case, post your code, I'm sure we can fix it.
Jun 06 2023
On Wednesday, 7 June 2023 at 00:18:54 UTC, Steven Schveighoffer wrote:So for instance, you can do: ```d immutable string[] strs = mod1.makeStrings() ~ mod2.makeStrings() ~ ...; ``` In a centralized place. -SteveHi, So what if I wanted to build the strings within my library but have the client append their own data, for example if I want to have declarative extensions? Could this be done by using a mixin template to create the strings in the client?
Jun 15 2023
On 6/15/23 9:59 PM, Mark Fisher wrote:Hi, So what if I wanted to build the strings within my library but have the client append their own data, for example if I want to have declarative extensions? Could this be done by using a mixin template to create the strings in the client?Well, as long as it's not *compile time*, but runtime, you can definitely do it. Just use shared static constructors. As far as I know, there's no way to have the compiler build a compile-time list of all compiled modules to be used to build such a thing. You might be able to do it as a pre-build step. One thing you could do is have a convention where some "master" module that knows all of the important modules to includes passes it to some mixin to instantiate. -Steve
Jun 15 2023