3

In the Julia manual metaprogramming section, we see the following example for how to use interpolation in an expression:

julia> ex = :(a in $:((1,2,3)) )
:($(Expr(:in, :a, :((1,2,3)))))

Given that I can create another expression

julia> ex1 = :(a in (1,2,3) )
:($(Expr(:in, :a, :((1,2,3)))))

julia> ex == ex1
true

Is there any reason for the extra $:(...) in the manual's example? Or is it just to indicate possibilities of this construction -- that $ and :(...) are "inverses"?

Micah Smith
  • 4,203
  • 22
  • 28
  • I think this is simply a case where those examples could use some improvement. Yes, I think the point is to demonstrate the splicing of an expression literal, but it's not very useful or instructive. And the following example looks like it's broken. Using `in` isn't that great, either, since it doesn't print out very nicely (as compared to other operators). Would you be willing to try replacing those examples with ones that you think would be more instructive? It's quite easy to edit the documentation right on GitHub. – mbauman Jun 30 '15 at 22:24
  • @MattB. Thanks for your comments, yes, I do that the manual could be clearer in this case. I was thinking that the answer [here](http://stackoverflow.com/a/23482257/2514228) could be a good starting point for improvement. I'll see if I can come up with something. – Micah Smith Jul 01 '15 at 14:34
  • You could also use `parse("a in (1, 2, 3)")` in order to get: `:($(Expr(:in, :a, :((1,2,3)))))` – HarmonicaMuse Jul 03 '15 at 10:51

0 Answers0