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
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?
This might be helpful?
julia> @enum P n h m l
n = 0
h = 1
m = 2
l = 3
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:
(one::P = 0, two::P = 1, three::P = 2, four::P = 3, five::P = 4)
@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