Expressions and macros

Metaprogramming is fun, and Julia definitely has one of the best metaprogramming features compared with some of its rivals. The initial cues and inspiration have been taken from Lisp, and similarly to Lisp, Julia is written in Julia itself—or in other words, Julia is homoiconic.

To explain how Julia interprets a code, here is a small code snippet:

julia> code = "println(\"hello world \")"
"println(\"hello world \")"

julia> expression = parse(code)
:(println("hello world "))

julia> typeof(expression)

Here, we have simply passed a normal Julia code println("hello world") as a string to the function parse. This function, in turn, takes this piece of string and converts it into a data type called Expr, which is evident ...

Get Learning Julia now with O’Reilly online learning.

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