The length of a enum object in julia?

I was wondering, is there a quick julia way to get the length of an enum type? For example, something like
@enum P n h m l
and then len(P) or length(P) would return 3?

EDIT: one more side note, I do not quite understand why did this enum type start counting from 0, not from 1? I thought Julia is more matlab/math friendly, by that I mean it usually gets counting from 1, not 0, right?

1 Like

This might be helpful?

julia> @enum P n h m l

julia> P
Enum P:
n = 0
h = 1
m = 2
l = 3

julia> P.size

No, I don’t think so:

julia> @enum P one two; P.size

julia> @enum P one two three four five; P.size

This is the size of the type in bytes, I think. This works:

julia> instances(P)
(one::P = 0, two::P = 1, three::P = 2, four::P = 3, five::P = 4)

julia> length(instances(P))

@mauro3, I tested it. It looks that instances(P) would return a tuple of all the enumerated elements. And length(instances(P)) would return the length of that tuple, which is the length needed.
Thank you both so much for the clarification. This makes Julia learning a much better experience. @nilshg, @mauro3