Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Julia Cookbook

You're reading from   Julia Cookbook Over 40 recipes to get you up and running with programming using Julia

Arrow left icon
Product type Paperback
Published in Sep 2016
Publisher
ISBN-13 9781785882012
Length 172 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Raj R Jalem Raj R Jalem
Author Profile Icon Raj R Jalem
Raj R Jalem
Jalem Raj Rohit Jalem Raj Rohit
Author Profile Icon Jalem Raj Rohit
Jalem Raj Rohit
Arrow right icon
View More author details
Toc

Interpolation

Sometimes, construction on Expression objects is difficult, especially when you have multiple objects and/or variables. This is used for easy and readable expression construction.

So, interpolation is a way to deal with this. Such objects can be interpolated into the expression construction through a $ prefix. This process is also called splicing expressions, variables, or literals into quoted expressions.

How to do it...

Suppose there is a literal p, which has to be interpolated for constructing an expression with other literals; this is how it would be done:

p = 6;
exp = :(20 + $p)

This is how it would look:

How to do it...

For nested quoting, each symbol must be quoted separately, along with splicing the overall parentheses of the nested expression:

p = 6;
q = 7;
:(:p in $(  :(:p * :q ) ) )

This is how it would look in the REPL:

How to do it...

Even data structures can be spliced into an expression construction. Now, let's consider the tuple data structure for splicing into an expression builder...

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