Reflection capabilities
We saw in this chapter that the code in Julia is represented by expressions that are data structures of type Expr
. 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 already have encountered many of these functions before:
typeof
andsubtypes
to query the typehierarchy
(refer to Chapter 6, More on Types, Methods, and Modules)methods(f)
to see all the methods of a functionf
(refer to Chapter 3, Functions)names
andtypes
: given a typePerson
:type Person name:: String height::Float64 end
Then,
names(Person)
returns the field names as symbols:2-element Array{Symbol,1}: ...
Get Getting Started with Julia now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.