Reader small image

You're reading from  Julia Cookbook

Product typeBook
Published inSep 2016
Reading LevelBeginner
Publisher
ISBN-139781785882012
Edition1st Edition
Languages
Concepts
Right arrow
Authors (2):
Jalem Raj Rohit
Jalem Raj Rohit
author image
Jalem Raj Rohit

Jalem Raj Rohit is an IIT Jodhpur graduate with a keen interest in recommender systems, machine learning, and serverless and distributed systems. Raj currently works as a senior consultantdata scienceand NLP at Episource, before which he worked at Zomato and Kayako. He contributes to open source projects in Python, Go, and Julia. He also speaks at tech conferences about serverless engineering and machine learning.
Read more about Jalem Raj Rohit

View More author details
Right arrow

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 page is locked
Previous PageNext Page
You have been reading a chapter from
Julia Cookbook
Published in: Sep 2016Publisher: ISBN-13: 9781785882012

Authors (2)

author image
Jalem Raj Rohit

Jalem Raj Rohit is an IIT Jodhpur graduate with a keen interest in recommender systems, machine learning, and serverless and distributed systems. Raj currently works as a senior consultantdata scienceand NLP at Episource, before which he worked at Zomato and Kayako. He contributes to open source projects in Python, Go, and Julia. He also speaks at tech conferences about serverless engineering and machine learning.
Read more about Jalem Raj Rohit