This seems like it should be simple, but it’s still tripping me up. I need to write a function that gives this result:
julia> f(:x)
:(someArray[:x])
Interpolation gives me a “raw” x, and I’m having a surprisingly hard time making a Symbol of it.
On a side note, it seems like this kind of thing happens a lot in metaprogramming. Something that seems like it ought to be simple just… isn’t. Is this just me? Or metaprogramming in Julia? Or something about metaprogramming in general?
I’ve read that in general macros aren’t composable, but in this case there aren’t any macros involved. Do we need more (or better) tools or combinators for this stuff? Or maybe a way to build the right mental model?
Julia is already much easier than it would be to produce similar results in something like Python. So it feels like I’m making progress and getting quicker at it. It’s just a bit frustrating for simple things like this to be throwing me.
Something that I’ve always found very confusing is that there is QuoteNode(x), but there is also Expr(:quote, x). As far as I can tell these two are functionally equivalent, even though they have completely different data types. I would like some clarification of why QuoteNode exists as well.
I believe QuoteNode is documented in the dev doc (on my phone, didn’t check)
The two are not equivalent. The Expr(:quote) support interpolation expression when evaluated. QuoteNode simply return the quoted value. It’s like the difference between the quote and backquote in lisp.