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)
Expr

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 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.