Enumeration (enum) types

BlitzMax Forums/BlitzMax Programming/Enumeration (enum) types

The inclusion of arrays addition in Blitzmax 1.26 has given us the ability to simulate Enumeration..

Try this:
Const SYM_A% = 1
Const SYM_B% = 2
Const SYM_C% = 3
Const SYM_D% = 4
Const SYM_E% = 5
Const SYM_F% = 6

Local symbol:TEnum = New TEnum

Local a%[] = [SYM_F,SYM_E,SYM_D]
Local b%[] = [SYM_A,SYM_B,SYM_C]

symbol.value = SYM_D
If Symbol.in( a+b ) Then DebugLog "Yes it's found"

showSymbols( a+b )

'########################################
Function showSymbols( list%[] )
	For Local item% = EachIn list
		DebugLog item
	Next
End Function

'########################################
Type TEnum
	Field value%

	'----------------------------------------
	Method in( list%[] )
		For Local item% = EachIn list
			If value=item Then Return True
		Next
	Return False
	End Method
End Type


Not typesafe, so not technically an enumerator.

True, but it simulates the functionality quite well.

We can already simulate Enumeration, by simply typing the numbers in.

We can already simulate Enumeration, by simply typing the numbers in.

Heh... that's how I simulate key-presses ;-)

We can simulate constants like that too :)

It just seems to compicated for me. I know I was glib, but apart from the speed of not having to type = XX, I cannot see how your replacement would be of use to me. (Cos I would forget how it worked and introduce error where none were before)

Fair enough well done, and it is and example of array addition I suppose. Just not very useful. (The not very useful bit is my opinon, if anyone does find it useful, then obviously it is useful)