Reflection capabilities

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 if a is not declared, you get:
@isdefined a #> false
  • Use the typeof and InteractiveUtils.subtypes to query the type hierarchy (refer to Chapter 6, More on Types, Methods, and Modules)
  • Use the methods(f) to see all the methods of a function ...

Get Julia 1.0 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.