Meta programming gurus, how can I create a struct from two Symbols?
So say I have two arrays of symbols, and I want to create types (and set their abstract type) from all their possible combinations, it would look kind of (but not quite) like this:
abstract type AbstractType end
for x in [:A, :B], y in [:Y, :Z]
struct $x$y <: AbstractType end
end
and the result would mean that the following would be defined:
struct AY <: AbstractType end
struct AZ <: AbstractType end
struct BY <: AbstractType end
struct BZ <: AbstractType end
I suspect you are right. I have a bunch of factors and these have discrete levels. Like Food: fruit, meat, bread… I want to create methods that dispatch on distinct setups, unique collections of factors-level pairs. For that I need to code the factors and their levels as types. I think…
This looks very promising indeed. Fits right in. But how would I build a NamedTuple “on the fly”? Say I have a Dict where the keys are to be the names in the NamedTuple and the values the values. How can I construct a NamedTuple out of that…?
Wah, I’m sure. Right now I don’t “get it”, but maybe once I start writing the methods for my named tuples I’ll understand EponymTuples better.
Wait a minute, the dispatch is matched on the actual names and only the types of the values for NamedTuples, not the actual values of the values…
So a function that only accepts a will also accept b, cause the type signatures will be identical for both a and b:
a = (:food = :apple, :container = :box)
b = (:food = :meat, :container = :can)
Am I missing something? If that is the case then I’ll need to think this over. All my factor names (i.e. the name part of the named tuple) are always the same. It’s the specific level (i.e. the value part of the named tuple) that changes… It’s the level I want to dispatch on.