Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Julia 1.0 Programming

You're reading from   Julia 1.0 Programming Dynamic and high-performance programming to build fast scientific applications

Arrow left icon
Product type Paperback
Published in Sep 2018
Publisher
ISBN-13 9781788999090
Length 196 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ivo Balbaert Ivo Balbaert
Author Profile Icon Ivo Balbaert
Ivo Balbaert
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Installing the Julia Platform FREE CHAPTER 2. Variables, Types, and Operations 3. Functions 4. Control Flow 5. Collection Types 6. More on Types, Methods, and Modules 7. Metaprogramming in Julia 8. I/O, Networking, and Parallel Computing 9. Running External Programs 10. The Standard Library and Packages 11. Other Books You May Enjoy

Evaluation and interpolation


With the definition of type Expr from the preceding section, we can also build expressions directly from the constructor for Expr. For example: e1 = Expr(:call, *, 3, 4) returns :((*)(3, 4)) (follow along with the code in Chapter 7\eval.jl).

The result of an expression can be computed with the eval function, eval(e1), which returns 12 in this case. At the time an expression is constructed, not all the symbols have to be defined, but they have to be defined at the time of evaluation, otherwise an error occurs.

For example, e2 = Expr(:call, *, 3, :a) returns :((*)(3, a)), and eval(e2) then gives ERROR: UndefVarError: a not defined. Only after we say, for example, a = 4 does eval(e2) return 12.

Expressions can also change the state of the execution environment, for example, the expression e3 = :(b = 1) assigns a value to b when evaluated, and even defines b, if it doesn't exist already.

 

To make writing expressions a bit simpler, we can use the $ operator to do interpolation...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image