Can't we create a macro named "?"

julia> @? meca
┌ Error: Failed to revise C:\Users\joaqu\.julia\dev\GMT\src\common_options.jl
│   exception =
│    LoadError: "invalid identifier name \"?\""

But we have the broadcast macro @. (which I can’t find the definition) and if I try to create another @. I get the same error

LoadError: "invalid identifier name \".\""

So with some trickery it seems to be possible. How?

Thanks

2 Likes

One way is:

julia> macro var"?"(ex)
         @show ex
         nothing
       end
@? (macro with 1 method)

julia> @? c1 ? 1 : c2 ? 2 : 3
ex = :(if c1
      1
  else
      if c2
          2
      else
          3
      end
  end)
2 Likes

Cool, thanks.