We saw in this chapter that code in Julia is represented by expressions that are data structures of the Expr
type. The structure of a program and its types can therefore be explored programmatically just like any other data. This means that a running program can dynamically discover its own properties, which is called reflection. We have already encountered some of these macros or functions before:
- Use the
@isdefined
macro to check whether a variable is already declared, for example ifa
is not declared, you get:
@isdefined a #> false
mutable struct Person name:: String height::Float64 end
Then, fieldnames(Person)
returns the field names as a tuple of symbols: (:name, :height)
Person.types
returns a tuple...