Comparing enum constructors?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Comparing enum constructors?

Mihail Ivanchev
Hi List,

what is an elegant way to compare the constructors (ignoring parameters) of two enum instances? I can do it using Type but I am feeling uncomfortable with that solution.

Regards,
Mihail

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Comparing enum constructors?

Mihail Ivanchev
OK, I am not even able to do it with Type, HALP plz!!

On Mon, Nov 7, 2011 at 7:17 PM, Mihail Ivanchev <[hidden email]> wrote:
Hi List,

what is an elegant way to compare the constructors (ignoring parameters) of two enum instances? I can do it using Type but I am feeling uncomfortable with that solution.

Regards,
Mihail


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Comparing enum constructors?

sledorze
double switch?
Reply | Threaded
Open this post in threaded view
|

Re: Comparing enum constructors?

Nicolas Cannasse
In reply to this post by Mihail Ivanchev
Le 07/11/2011 19:28, Mihail Ivanchev a écrit :
> OK, I am not even able to do it with Type, HALP plz!!

If you want to ignore parameters:

Type.enumIndex(a) == Type.enumIndex(b)
(or Type.enumConstructor as well)

If you want to recurse on parameters :

Type.enumEq(a,b)

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Comparing enum constructors?

sledorze
talking about that; ..
when ttrying to use 'Type' (not haxe.macro.Type),  I got this:

../../../Motion-Twin/haxe/std/haxe/macro/Type.hx:52: characters 1-25 : Invalid package : <empty> should be haxe.macro

what's the solution?
Stephane
Reply | Threaded
Open this post in threaded view
|

Re: Comparing enum constructors?

Jan_Flanders
Related thread/issue: http://haxe.1354130.n2.nabble.com/How-does-haXe-locate-types-really-td6912368.html (answer/suggestion in the last response)

Jan

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Comparing enum constructors?

Johann Borck
In reply to this post by sledorze
On 11/07/2011 10:42 PM, sledorze wrote:
> talking about that; ..
> when ttrying to use 'Type' (not haxe.macro.Type),  I got this:
>
> ../../../Motion-Twin/haxe/std/haxe/macro/Type.hx:52: characters 1-25 :
> Invalid package :<empty>  should be haxe.macro
>
> what's the solution?
Hard to say without any code. When I'm using both in the same file, I use typedef RootType = Type;
before importing haxe.macro.Type.

regards,
Johann

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Comparing enum constructors?

sledorze
Okay, looks like it works if I surround them with #if macro (which I forgot in the first place - :) )

Thanks both of you!