Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-10-02 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 17 September 2020 at 01:57:39 UTC, Mike Parker wrote: On Thursday, 17 September 2020 at 00:32:40 UTC, Cecil Ward So can the result of declaring certain things with enum ever have an _address_ then? (According to legit D code that is, never mind the underlying implementation

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-18 Thread claptrap via Digitalmars-d-learn
On Friday, 18 September 2020 at 02:49:30 UTC, Mike Parker wrote: On Thursday, 17 September 2020 at 22:25:47 UTC, claptrap wrote: If enum means manifiest constant, or compile time constant, then it makes more sense, as you allude to in a later post. But 'enum' is a terrible name for that and I

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 17 September 2020 at 22:25:47 UTC, claptrap wrote: If enum means manifiest constant, or compile time constant, then it makes more sense, as you allude to in a later post. But 'enum' is a terrible name for that and I dont think my brain will ever stop finding it incongruous. And

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread jmh530 via Digitalmars-d-learn
On Thursday, 17 September 2020 at 10:53:48 UTC, Mike Parker wrote: [snip] I can attest that in the 17 years I've been hanging around here, the fact that enum is used to indicate a manifest constant has not been a serious source of WTF posts. So I think "pretty much everyone coming to D" have

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread claptrap via Digitalmars-d-learn
On Thursday, 17 September 2020 at 10:56:28 UTC, Mike Parker wrote: On Thursday, 17 September 2020 at 09:44:20 UTC, claptrap wrote: Seriously how it's implemented is irrelevant. And to be clear, my point wasn't about how it's implemented. My point was that: enum { foo = 10; } and enum

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 17, 2020 at 06:06:56PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 9/17/20 9:13 AM, Simen Kjærås wrote: > > > To be clear: I don't mind 'enum' being used this way, but if I were > > to do things over again, I would have used 'alias'. > > fun fact: for a (very)

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/17/20 9:13 AM, Simen Kjærås wrote: To be clear: I don't mind 'enum' being used this way, but if I were to do things over again, I would have used 'alias'. fun fact: for a (very) brief time, D had a `manifest` keyword that did exactly what enum does in this instance (not even sure it

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 17 September 2020 at 13:25:08 UTC, Mike Parker wrote: Well, I was already using anonymous enums for compile-time And, I should add, I have *never* seen C enums as an enumerated list of values. I've always seen them as an alternative for #defined constants because they're

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 17 September 2020 at 13:13:46 UTC, Simen Kjærås wrote: To quote Bill Baxter from way back when (https://forum.dlang.org/post/fjdc4c$2gft$1...@digitalmars.com): > Why does: > final int x = 3; > make any more intuitive sense than: > enum int x = 3; > ? There are these

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 17 September 2020 at 10:56:28 UTC, Mike Parker wrote: On Thursday, 17 September 2020 at 09:44:20 UTC, claptrap wrote: Seriously how it's implemented is irrelevant. And to be clear, my point wasn't about how it's implemented. My point was that: enum { foo = 10; } and enum

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Thursday, 17 September 2020 at 10:56:28 UTC, Mike Parker wrote: Are effectively the same thing, whether it's implemented that way or not. So why on earth would a new keyword be necessary? C++ made enums stricter by "enum class".

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 17 September 2020 at 09:44:20 UTC, claptrap wrote: Seriously how it's implemented is irrelevant. And to be clear, my point wasn't about how it's implemented. My point was that: enum { foo = 10; } and enum foo = 10; Are effectively the same thing, whether it's implemented

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 17 September 2020 at 09:44:20 UTC, claptrap wrote: Names are important, principle of least astonishment and all that, pretty much everyone coming to D is going be WTF in learning about that. And if you keep overloading existing keywords with more and more meanings the code gets

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread claptrap via Digitalmars-d-learn
On Thursday, 17 September 2020 at 01:57:39 UTC, Mike Parker wrote: On Thursday, 17 September 2020 at 00:32:40 UTC, Cecil Ward enum foo is essentially a shortcut for enum { foo }. It’s neither bent out of shape nor twisted. Consider that C++ added the new keyword constexpr for the same thing.

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-16 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 17 September 2020 at 00:32:40 UTC, Cecil Ward So can the result of declaring certain things with enum ever have an _address_ then? (According to legit D code that is, never mind the underlying implementation details, which may not be observable) No. Think of it as a named

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-16 Thread Cecil Ward via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 17:19:13 UTC, Adam D. Ruppe wrote: On Wednesday, 16 September 2020 at 17:12:47 UTC, Cecil Ward wrote: then is there any downside to just using enum all the time? For a non-string array, enum may give runtime allocations that static immutable won't.

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 17:12:47 UTC, Cecil Ward wrote: then is there any downside to just using enum all the time? For a non-string array, enum may give runtime allocations that static immutable won't. Generally think of enum as being replaced with the literal representation

enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-16 Thread Cecil Ward via Digitalmars-d-learn
A really stupid question, I fear. If I have some kind of declaration of some ‘variable’ whose value is strictly known at compile time and I do one of the following (rough syntax) either enum foo = bar; or const foo = bar; or immutable foo = bar; then is there any downside to just