Hi Guys,
I'm wondering if there is an equivalent to jai's "use" for structs/objects, this construct allows for objects within an object to be "expanded" to their members at compile time, so in nim it would be something like this:
type
Entity = object
id: int
health: int
Velocity = object
speed: int
Person = object
# use? Entity
# use? Velocity
person_stuff: string
let person = Person(id: 5, health: 20, speed: 45, person_stuff: "whatever")
I'm sure a macro can do this but is there an easier way?
Thanks for any help :)
A couple of template accessors usually do the job:
template id*(p: Person): int = p.entity.id
template health*(p: Persons): int = p.entity.health
You could automate the template generation via a type introspecting macro, but you ain't gonna need it. Probably you also don't need the shortcuts either. You should introduce shortcuts and syntactic sugar when it pays off, not because it's cool and some other languages have it.