enum fake out

BlitzMax Forums/BlitzMax Programming/enum fake out

Warren(Posted 2005) [#1]
I came up with, what I think, is the best alternative for proper enum vars in BlitzMax. Yes, you still have to number everything by hand, but at least you can use them as you would in a .NET language...


Type EStatus

	Global Open		= 0
	Global Closed		= 1
	Global Waiting	= 2

End Type

MyStatus = EStatus.Closed
Print MyStatus
WaitKey



N(Posted 2005) [#2]
You know, I suggested this in the last Enums thread. Might want to put 'Final' after EStatus so that it can't be inherited.


Warren(Posted 2005) [#3]
Congrats. This just occurred to me this morning so I figured I'd throw another stone in the pool.

No biggie.


marksibly(Posted 2005) [#4]
Hi,

Using Consts instead of Globals will be safer and more efficient.


Warren(Posted 2005) [#5]
Having actual enums in the language would be the ideal solution. :)


N(Posted 2005) [#6]
Agree with Warren here.

How hard could it be to add them? Heck, you could probably just preprocess the code to spit out a type with constant fields and it'd still work.

PLEASE ADD ENUMS.

That's my request- and since it's my birthday soon, I may as well put it in ;)


flying willy(Posted 2005) [#7]
how about a small program to generate consts with seq nums?


Warren(Posted 2005) [#8]
There are a hundred work arounds. However, the best solution remains for Mark to add them to the language. As Noel pointed out, it's as simple as added a preprocessing step to convert them into const vars internally. Should be quick and painless to add to the compiler...


Matthew Smith(Posted 2005) [#9]
Mark, any thoughts on adding these to the language?


FlameDuck(Posted 2005) [#10]
How hard could it be to add them? Heck, you could probably just preprocess the code to spit out a type with constant fields and it'd still work.
Then they wouldn't be typesafe tho', would they?


Warren(Posted 2005) [#11]
That doesn't make any sense. The compiler preprocesses them into const lines before beginning compilation - it's the exact same effect as if I had typed in the const lines myself.


N(Posted 2005) [#12]
Then they wouldn't be typesafe tho', would they?


It's a bunch of constants- does it really matter?


FlameDuck(Posted 2005) [#13]
That doesn't make any sense. The compiler preprocesses them into const lines before beginning compilation - it's the exact same effect as if I had typed in the const lines myself.
An enumerator can be used for more than just 'runtime constants' you know.

It's a bunch of constants- does it really matter?
No it isn't, and yes it does.


Bot Builder(Posted 2005) [#14]
Perhaps it can in other languages, but what says that a bmax enumerator has to be anything other than compile-time constants?


FlameDuck(Posted 2005) [#15]
Perhaps it can in other languages, but what says that a bmax enumerator has to be anything other than compile-time constants?
Because otherwise you could just as well write them all by hand, or auto-generated.


Bot Builder(Posted 2005) [#16]
Yep. Thing is, Bmax doesn't auto-generate them.

/me adds to list of things for pre-processor


flying willy(Posted 2005) [#17]
IMHO

the language should have enums

Strict

and

Stricter

Stricter is case sensitive.


Warren(Posted 2005) [#18]
An enumerator can be used for more than just 'runtime constants' you know.

Every language I've ever used has one use for the keyword "enum" - a list of automatically generated values (or you can specify them by hand, but that's not the common usage). Which other features are supported that I'm not remembering?

Like I said, preprocess the enum list into a list of const lines and then compile my program. Simple, and should take Mark all of 10 minutes.


N(Posted 2005) [#19]
Simple, and should take Mark all of 10 minutes.


You have to remember that it took Mark all of- what, 3 years?- to add normal and cube mapping to Blitz3D. What might take you ten minutes may take him a couple years. ;)