Re: Enums and immutables

2017-03-18 Thread ag0aep6g via Digitalmars-d-learn
On 03/18/2017 01:22 PM, Oleg B wrote: enum arr = cast(ubyte[])[0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4]; auto arr1 = cast(void[])arr; immutable arr2 = cast(immutable(void)[])arr; enum arr3 = cast(void[])arr; Aside: The casts here do nothing to affect the outcome. writeln(cast(ush

Re: Enums and immutables

2017-03-18 Thread rikki cattermole via Digitalmars-d-learn
On 19/03/2017 1:22 AM, Oleg B wrote: Hello. I found strange behavior while casting enum array and immutable array. import std.stdio; void main() { enum arr = cast(ubyte[])[0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4]; auto arr1 = cast(void[])arr; immutable arr2 = cast(immutable(void)[])arr;

Re: enums

2014-06-01 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 31 May 2014 at 22:45:32 UTC, bearophile wrote: Chris Nicholson-Sauls: Good... I was starting to fear I was the only one. In general you can't fix the names in a language because you always find someone that likes the ones present :) I think "enum" is a bad name for the purpose

Re: enums

2014-06-01 Thread Philippe Sigaud via Digitalmars-d-learn
On Sat, May 31, 2014 at 10:14 PM, bearophile via Digitalmars-d-learn wrote: >> In contrast to those two examples where immutable can be used at compile >> time, what are some other cases where it is necessary to use enum instead >> of immutable? > > > By default use enum if you define a compile-t

Re: enums

2014-05-31 Thread bearophile via Digitalmars-d-learn
Chris Nicholson-Sauls: Good... I was starting to fear I was the only one. In general you can't fix the names in a language because you always find someone that likes the ones present :) I think "enum" is a bad name for the purpose of defining manifest constants, but I don't think this will

Re: enums

2014-05-31 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 31 May 2014 at 22:13:35 UTC, monarch_dodra wrote: On Saturday, 31 May 2014 at 21:21:59 UTC, Paul D Anderson wrote: 'enum' as a manifest constant keyword has been an unpopular decision from its introduction. "Everybody" agrees that it should be changed. Everybody but Walter I find

Re: enums

2014-05-31 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 31 May 2014 at 21:21:59 UTC, Paul D Anderson wrote: 'enum' as a manifest constant keyword has been an unpopular decision from its introduction. "Everybody" agrees that it should be changed. Everybody but Walter I find enum makes sense.

Re: enums

2014-05-31 Thread Timon Gehr via Digitalmars-d-learn
On 05/31/2014 11:21 PM, Paul D Anderson wrote: On Saturday, 31 May 2014 at 20:14:59 UTC, bearophile wrote: Miles Stoudenmire: In contrast to those two examples where immutable can be used at compile time, what are some other cases where it is necessary to use enum instead of immutable? By de

Re: enums

2014-05-31 Thread bearophile via Digitalmars-d-learn
Paul D Anderson: 'enum' as a manifest constant keyword has been an unpopular decision from its introduction. I agree, I too asked for a better name. Bye, bearophile

Re: enums

2014-05-31 Thread Paul D Anderson via Digitalmars-d-learn
On Saturday, 31 May 2014 at 20:14:59 UTC, bearophile wrote: Miles Stoudenmire: In contrast to those two examples where immutable can be used at compile time, what are some other cases where it is necessary to use enum instead of immutable? By default use enum if you define a compile-time-kno

Re: enums

2014-05-31 Thread bearophile via Digitalmars-d-learn
Miles Stoudenmire: In contrast to those two examples where immutable can be used at compile time, what are some other cases where it is necessary to use enum instead of immutable? By default use enum if you define a compile-time-known value, unless it's composed data like an array, etc. By

Re: enums

2014-05-31 Thread Miles Stoudenmire via Digitalmars-d-learn
In contrast to those two examples where immutable can be used at compile time, what are some other cases where it is necessary to use enum instead of immutable? On 31 May 2014 09:33, Andrej Mitrovic via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > This has been asked so many

Re: enums

2014-05-31 Thread Andrej Mitrovic via Digitalmars-d-learn
This has been asked so many times, is this info not on the website? We should have an article on the site explaining this in depth. OT: Sorry for top-quoting and over-quoting. On Friday, May 30, 2014, monarch_dodra via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Friday, 30

Re: enums

2014-05-30 Thread via Digitalmars-d-learn
Some explanation how the seemingly different concepts "enumerated value" and "manifest constant" are actually related: Let's start with the "classical" enums as they're known from C/C++. They are used to create lists of symbolic names: enum Color { YELLOW, PINK, BLUE }; Internally, each

Re: enums

2014-05-30 Thread Philippe Sigaud via Digitalmars-d-learn
On Fri, May 30, 2014 at 7:56 PM, Steven Schveighoffer wrote: > You can as long as the value is known at compile time: > > http://dpaste.dzfl.pl/5a710bd80ab0 Oh wow. And that works for static if also: http://dpaste.dzfl.pl/f87321a47834 Man. That opens some new possibilities.

Re: enums

2014-05-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On Fri, 30 May 2014 13:34:38 -0400, Philippe Sigaud via Digitalmars-d-learn wrote: On Fri, May 30, 2014 at 7:28 PM, Ali Çehreli wrote: On 05/30/2014 08:30 AM, Russel Winder via Digitalmars-d-learn wrote: enum double p0 = 0.0045; As others have already said, p0 is a manifest con

Re: enums

2014-05-30 Thread Philippe Sigaud via Digitalmars-d-learn
On Fri, May 30, 2014 at 7:28 PM, Ali Çehreli wrote: > On 05/30/2014 08:30 AM, Russel Winder via Digitalmars-d-learn wrote: > >> enum double p0 = 0.0045; > > As others have already said, p0 is a manifest constant. Interestingly, it > can be thought of like a C macro, being pasted inside so

Re: enums

2014-05-30 Thread Ali Çehreli via Digitalmars-d-learn
On 05/30/2014 08:30 AM, Russel Winder via Digitalmars-d-learn wrote: > enum double p0 = 0.0045; As others have already said, p0 is a manifest constant. Interestingly, it can be thought of like a C macro, being pasted inside source code. Avoid enums for arrays and associative arrays a

Re: enums

2014-05-30 Thread Philippe Sigaud via Digitalmars-d-learn
A good use of 'static immutable', sadly not voted into the language. :-) But you're right, and I remember being tripped by this.

Re: enums

2014-05-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 30, 2014 at 07:17:15PM +0200, Philippe Sigaud via Digitalmars-d-learn wrote: > > In D enum can be used to define manifest constants. This means > > constants known at compile time. In practice for a double there > > isn't a lot of difference. In general you can't take the address of >

Re: enums

2014-05-30 Thread Philippe Sigaud via Digitalmars-d-learn
> In D enum can be used to define manifest constants. This means constants > known at compile time. In practice for a double there isn't a lot of > difference. In general you can't take the address of a manifest constant, > unlike immutables. Because they do not exist as 'variables' or symbol in t

Re: enums

2014-05-30 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 30 May 2014 at 15:30:15 UTC, Russel Winder via Digitalmars-d-learn wrote: I think I have no idea what D enums are about. Bearophile's example of some code in an email on another thread uses: enum double p0 = 0.0045; Now I would have written: immutable double p0 =

Re: enums

2014-05-30 Thread bearophile via Digitalmars-d-learn
Russel Winder: For me, enum means create an enumerated type. Thus "enum double" to define a single value is just a contradiction. Enlightenment required… In D enum can be used to define manifest constants. This means constants known at compile time. In practice for a double there isn't a l

Re: enums

2009-03-16 Thread Jarrett Billingsley
On Mon, Mar 16, 2009 at 2:53 PM, Nicholas Jordan wrote: > Oops, I missed the note about enums. > > enums in other languages sound to me to be a great idea, but when I first > started coding I noted that the machine was > placing them at the beginning of the file and I eventually figured out that