Extending JuMP.@constraint macro: misunderstanding scope?

Macros are nontrivial to write. You should thoroughly read all of the documentation. Metaprogramming · The Julia Language

In particular, using eval in a macro is a clear sign that the approach is wrong. Macros should basically take an expression and return a new expression based on the syntax, not the type. They should never evaluate the actual values of the input arguments.

So that means you can’t do things like if typeof(x) :< Foo.

That being said I’m starting to realise that this is probably not worth it

It’s probably easier to overload Base.setindex!on gep so you could go gep[:con1] = @constraint(...).

4 Likes