I think it’s because of your extra spacing around the .. This seems to work:
julia> mod = :MyModule
:MyModule
julia> f = :sin
:sin
julia> :(import .$mod: $f)
:(import .MyModule: sin)
Once in a while, I get stuck with this kind of problem. If I can’t write the expression with quote, I just dump what I want to produce, and build it “manually” with Expr and such. It’s uglier, but it always works.
julia> dump(:(import .MyModule: sin))
Expr
head: Symbol import
args: Array{Any}((1,))
1: Expr
head: Symbol :
args: Array{Any}((2,))
1: Expr
head: Symbol .
args: Array{Any}((2,))
1: Symbol .
2: Symbol MyModule
2: Expr
head: Symbol .
args: Array{Any}((1,))
1: Symbol sin
As an aside, reading your code, I would just esc(quote ... end), instead of escaping individual elements…