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