Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Julia Cookbook

You're reading from  Julia Cookbook

Product type Book
Published in Sep 2016
Publisher
ISBN-13 9781785882012
Pages 172 pages
Edition 1st Edition
Languages
Authors (2):
Raj R Jalem Raj R Jalem
Jalem Raj Rohit Jalem Raj Rohit
Profile icon Jalem Raj Rohit
View More author details

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:

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:

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

p = 6...
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 €14.99/month. Cancel anytime}