I am building up a stochastic transition matrix, and I want to use constants for the indices of various states to avoid errors, eg
P[state_A, state_B] = some_probability P[state_A, sink] = death_probability ...
I can do it with
const state_A = 1 etc.
@enum States state_A=1 ... would be so much nicer, but this does not work directly. I can define
Base.getindex(A::AbstractArray, inds::Enum...) = getindex(A, [convert(Int, e) for e in inds]...) Base.setindex!(A::AbstractArray, X, inds::Enum...) = setindex!(A, X, [convert(Int, e) for e in inds]...)
but it is a bit heavy-handed, and does not support mixtures of enums and ints, let alone
Is there an elegant trick that would make it work, or should I stick to
consts, maybe with a nice macro like
macro const_indexes(names...) quote $([:(const $(esc(name)) = $(index)) for (index, name) in enumerate(names)]...) end end