digitalmars.D.learn - "version" private word
- Igor Shirkalin (15/15) Oct 31 2017 Hello!
- Jacob Carlborg (13/32) Oct 31 2017 The only alternative is to do something like this:
- Igor Shirkalin (2/32) Oct 31 2017 Got it. Thank you!
- bauss (4/41) Oct 31 2017 Yeah, in Diamond I went with this approach to make conditional
- Dr. Assembly (4/34) Oct 31 2017 Why is that keyword called enum? is this any related to the fact
- Igor Shirkalin (5/26) Oct 31 2017 You're right. Enum defines constant or group of constants in
- Dr. Assembly (4/31) Oct 31 2017 thanks. I just find it werid, maybe because I came from C/C++
- Jacob Carlborg (6/9) Oct 31 2017 Think of it more like #define in C/C++ than "const". The above defines a...
- Jonathan M Davis (18/25) Oct 31 2017 Yeah, thinking about them as const would be bad. All enums (whether they...
- Jesse Phillips (5/6) Oct 31 2017 You goal should be to describe features.
- Igor Shirkalin (2/10) Oct 31 2017 pardon?
- Jesse Phillips (6/19) Oct 31 2017 Sorry I hate writing code on mobile.
- Igor Shirkalin (6/27) Oct 31 2017 The question was not about mobile platforms. Sometimes we need to
- Steven Schveighoffer (15/43) Oct 31 2017 I think he meant he didn't like writing code in a forum post on his
- Igor Shirkalin (8/39) Oct 31 2017 Ah. :)
- Basile B. (7/22) Nov 01 2017 I've implemented this in my PL:
Hello! We need some conditional compilation using 'version'. Say we have some code to be compiled for X86 and X86_64. How can we do that using predefined (or other) versions? Examples: version(X86 || X86_64) // failed version(X86) || version(X86_64) // failed The following works but it is too verbose: version(X86) { version = X86_or_64; } version(X86_64) { version = X86_or_64; } - IS
Oct 31 2017
On 2017-10-31 14:46, Igor Shirkalin wrote:Hello! We need some conditional compilation using 'version'. Say we have some code to be compiled for X86 and X86_64. How can we do that using predefined (or other) versions? Examples: version(X86 || X86_64) // failed version(X86) || version(X86_64) // failed The following works but it is too verbose: version(X86) { version = X86_or_64; } version(X86_64) { version = X86_or_64; }The only alternative is to do something like this: version (X86) enum x86 = true; else enum x86 = false; else version (X86_64) enum x86_64 = true; else enum x86_64 = false; static if (x86 || x86_64) {} -- /Jacob Carlborg
Oct 31 2017
On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote:On 2017-10-31 14:46, Igor Shirkalin wrote:Got it. Thank you!Hello! We need some conditional compilation using 'version'. Say we have some code to be compiled for X86 and X86_64. How can we do that using predefined (or other) versions? Examples: version(X86 || X86_64) // failed version(X86) || version(X86_64) // failed The following works but it is too verbose: version(X86) { version = X86_or_64; } version(X86_64) { version = X86_or_64; }The only alternative is to do something like this: version (X86) enum x86 = true; else enum x86 = false; else version (X86_64) enum x86_64 = true; else enum x86_64 = false; static if (x86 || x86_64) {}
Oct 31 2017
On Tuesday, 31 October 2017 at 13:55:56 UTC, Igor Shirkalin wrote:On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote:Yeah, in Diamond I went with this approach to make conditional compilation around the project much easier. https://github.com/DiamondMVC/Diamond/blob/master/core/apptype.dOn 2017-10-31 14:46, Igor Shirkalin wrote:Got it. Thank you!Hello! We need some conditional compilation using 'version'. Say we have some code to be compiled for X86 and X86_64. How can we do that using predefined (or other) versions? Examples: version(X86 || X86_64) // failed version(X86) || version(X86_64) // failed The following works but it is too verbose: version(X86) { version = X86_or_64; } version(X86_64) { version = X86_or_64; }The only alternative is to do something like this: version (X86) enum x86 = true; else enum x86 = false; else version (X86_64) enum x86_64 = true; else enum x86_64 = false; static if (x86 || x86_64) {}
Oct 31 2017
On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote:On 2017-10-31 14:46, Igor Shirkalin wrote:Why is that keyword called enum? is this any related to the fact enumeration's field are const values? it would be called invariable or something?Hello! We need some conditional compilation using 'version'. Say we have some code to be compiled for X86 and X86_64. How can we do that using predefined (or other) versions? Examples: version(X86 || X86_64) // failed version(X86) || version(X86_64) // failed The following works but it is too verbose: version(X86) { version = X86_or_64; } version(X86_64) { version = X86_or_64; }The only alternative is to do something like this: version (X86) enum x86 = true; else enum x86 = false; else version (X86_64) enum x86_64 = true; else enum x86_64 = false; static if (x86 || x86_64) {}
Oct 31 2017
On Tuesday, 31 October 2017 at 14:54:27 UTC, Dr. Assembly wrote:On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote:You're right. Enum defines constant or group of constants in compile time. The full description of enum can be found here: https://dlang.org/spec/enum.htmlOn 2017-10-31 14:46, Igor Shirkalin wrote:Why is that keyword called enum? is this any related to the fact enumeration's field are const values? it would be called invariable or something?[...]The only alternative is to do something like this: version (X86) enum x86 = true; else enum x86 = false; else version (X86_64) enum x86_64 = true; else enum x86_64 = false; static if (x86 || x86_64) {}
Oct 31 2017
On Tuesday, 31 October 2017 at 15:20:31 UTC, Igor Shirkalin wrote:On Tuesday, 31 October 2017 at 14:54:27 UTC, Dr. Assembly wrote:thanks. I just find it werid, maybe because I came from C/C++ background, where it means only integer types. So enum s = "foo"; is really werid. But I'll get used to it.On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote:You're right. Enum defines constant or group of constants in compile time. The full description of enum can be found here: https://dlang.org/spec/enum.htmlOn 2017-10-31 14:46, Igor Shirkalin wrote:Why is that keyword called enum? is this any related to the fact enumeration's field are const values? it would be called invariable or something?[...]The only alternative is to do something like this: version (X86) enum x86 = true; else enum x86 = false; else version (X86_64) enum x86_64 = true; else enum x86_64 = false; static if (x86 || x86_64) {}
Oct 31 2017
On 2017-10-31 16:36, Dr. Assembly wrote:thanks. I just find it werid, maybe because I came from C/C++ background, where it means only integer types. So enum s = "foo"; is really werid. But I'll get used to it.Think of it more like #define in C/C++ than "const". The above defines a manifest constant that are only available at compile time, i.e. you cannot take the address of a manifest constant. -- /Jacob Carlborg
Oct 31 2017
On Tuesday, October 31, 2017 20:36:57 Jacob Carlborg via Digitalmars-d-learn wrote:On 2017-10-31 16:36, Dr. Assembly wrote:Yeah, thinking about them as const would be bad. All enums (whether they're manifest constants or actual enum types) effectively get copy-pasted when they're used, and in the case of arrays, that can be really important to understand. String literals aren't a problem, but an enum that is any other type of dynamic array is going to end up allocating a new array every time you use it, whereas if you had a variable at module-scope or a static variable (regardless of whether the variable was mutable, const, or immutable), then there's an actual memory location involved, and the copy-pasting doesn't happen. But enums in general in D (both manifest constants and actual enum types) can be more than just int (though string is probably the most common aside from int). They can be pretty much any type whose values can be known at compile time, even including things like structs. So, while enum types _are_ int by default just like in C, D's enums are actually _way_ more powerful than C's enums. - Jonathan M Davisthanks. I just find it werid, maybe because I came from C/C++ background, where it means only integer types. So enum s = "foo"; is really werid. But I'll get used to it.Think of it more like #define in C/C++ than "const". The above defines a manifest constant that are only available at compile time, i.e. you cannot take the address of a manifest constant.
Oct 31 2017
On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:Hello!You goal should be to describe features. Version x86 ... Version = I can stand on my head ...
Oct 31 2017
On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote:On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:pardon?Hello!You goal should be to describe features. Version x86 ... Version = I can stand on my head ...
Oct 31 2017
On Tuesday, 31 October 2017 at 14:25:19 UTC, Igor Shirkalin wrote:On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote:Sorry I hate writing code on mobile. You can create an arbitrary version by assigning a symbol to it, use that symbol to describe a feature, assign that symbol for each architecture that supports it. Then write code in a version block of that symbol.On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:pardon?Hello!You goal should be to describe features. Version x86 ... Version = I can stand on my head ...
Oct 31 2017
On Tuesday, 31 October 2017 at 14:31:17 UTC, Jesse Phillips wrote:On Tuesday, 31 October 2017 at 14:25:19 UTC, Igor Shirkalin wrote:The question was not about mobile platforms. Sometimes we need to mix some combinations of code in one big project with or without some libraries, algorithms etc. I see what you mean and practically agree with you. But not everything depends on you (us).On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote:Sorry I hate writing code on mobile. You can create an arbitrary version by assigning a symbol to it, use that symbol to describe a feature, assign that symbol for each architecture that supports it. Then write code in a version block of that symbol.On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:pardon?Hello!You goal should be to describe features. Version x86 ... Version = I can stand on my head ...
Oct 31 2017
On 10/31/17 10:47 AM, Igor Shirkalin wrote:On Tuesday, 31 October 2017 at 14:31:17 UTC, Jesse Phillips wrote:I think he meant he didn't like writing code in a forum post on his mobile, so he wrote something more abstract :)On Tuesday, 31 October 2017 at 14:25:19 UTC, Igor Shirkalin wrote:The question was not about mobile platforms.On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote:Sorry I hate writing code on mobile. You can create an arbitrary version by assigning a symbol to it, use that symbol to describe a feature, assign that symbol for each architecture that supports it. Then write code in a version block of that symbol.On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:pardon?Hello!You goal should be to describe features. Version x86 ... Version = I can stand on my head ...Sometimes we need to mix some combinations of code in one big project with or without some libraries, algorithms etc. I see what you mean and practically agree with you. But not everything depends on you (us).The above response has been the standard D answer for as long as this question has been asked (and it has been asked a lot). Walter is dead-set against allowing boolean expressions in version statements. The anointed way is to divide your code by feature support, and then version those features in/out based on the platform you are on. For example, instead of "X86_or_X64", you would do "TryUsingSSE" or something (not sure what your specific use case is). However, enums and static if can be far more powerful. Version statements do not extend across modules, so you may have to repeat the entire scaffolding to establish versions in multiple modules. Enums are accessible across modules. -Steve
Oct 31 2017
On Tuesday, 31 October 2017 at 15:19:49 UTC, Steven Schveighoffer wrote:On 10/31/17 10:47 AM, Igor Shirkalin wrote:Ah. :)I think he meant he didn't like writing code in a forum post on his mobile, so he wrote something more abstract :)The question was not about mobile platforms.[...]Sorry I hate writing code on mobile. You can create an arbitrary version by assigning a symbol to it, use that symbol to describe a feature, assign that symbol for each architecture that supports it. Then write code in a version block of that symbol.Now I understand the irritation about my question. I'm sorry.Sometimes we need to mix some combinations of code in one big project with or without some libraries, algorithms etc. I see what you mean and practically agree with you. But not everything depends on you (us).The above response has been the standard D answer for as long as this question has been asked (and it has been asked a lot). Walter is dead-set against allowing boolean expressions in version statements.The anointed way is to divide your code by feature support, and then version those features in/out based on the platform you are on. For example, instead of "X86_or_X64", you would do "TryUsingSSE" or something (not sure what your specific use case is).This doesn't solve the case with combinations of different versions. Four different versions produce nine (+4) different variants. It's stupid to define 9 additional version constants.However, enums and static if can be far more powerful. Version statements do not extend across modules, so you may have to repeat the entire scaffolding to establish versions in multiple modules. Enums are accessible across modules.Yes, it's now clear for me what to do. Thanks!
Oct 31 2017
On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:Hello! We need some conditional compilation using 'version'. Say we have some code to be compiled for X86 and X86_64. How can we do that using predefined (or other) versions? Examples: version(X86 || X86_64) // failed version(X86) || version(X86_64) // failed The following works but it is too verbose: version(X86) { version = X86_or_64; } version(X86_64) { version = X86_or_64; } - ISI've implemented this in my PL: https://github.com/BBasile/yatol/blob/master/src/yatol/semantic/versions.d https://github.com/BBasile/yatol/blob/master/grammar/formal/peg.txt#L53 You will never see it in D for some reason, which is that Bright think that it's bug prone and easier to read (correct me if i'm wrong)
Nov 01 2017