3
votes

Why am I getting the error message below? (I'm fairly new to metaprogramming in Julia.) Thanks.

julia> d = :e
:e

julia> macroexpand(:(b.$d))
:(b.e)

julia> macroexpand(:($d.c))
:(e.c)

julia> macroexpand(:(b.$d.c))
ERROR: unsupported or misplaced expression $

julia> macroexpand(:(b.$(d).c))
ERROR: unsupported or misplaced expression $
1
looks like a bug that is fixed on 0.4, I get julia> macroexpand(:(b.$d.c)) :(b.e.c) Output of versioninfo(): Julia Version 0.4.0-dev+4630 Commit f299fed (2015-05-04 14:29 UTC) Platform Info: System: Linux (x86_64-redhat-linux) CPU: Intel(R) Xeon(R) CPU E5-2630 v2 @ 2.60GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge) LAPACK: libopenblas LIBM: libopenlibm LLVM: libLLVM-3.3 - ptb
what about just :(b.$d.c) instead of macroexpand(...)? - ptb
@ptb Thanks for the comments. ex = :(b.$d.c) throws the same error as above unfortunately. Must have something to do with the assignment operation. - Jeff
There's something really weird going on here. macroexpand shouldn't be needed and you shouldn't be getting that error message. It seems that ex = :((b.$d).c) will do what you want, though. - Toivo Henningsson

1 Answers

3
votes

This was a bug, issue filed here:

https://github.com/JuliaLang/julia/issues/10997

It has been fixed since. As indicated in the comments on the question, there are some hacky workarounds if you're stuck on an unfixed Julia version, but hopefully you can upgrade.