Is it possible to write something like:```op = :(&&)set = AndSet@eval f

is it possible to write something like:

op = :(&&)
set = AndSet
@eval do_some_operation(::$set, lhs, rhs) = lhs $op $rhs

? The $op part does not get parsed as hoped. Any way to rewrite this to make it possible?

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

Answered by @simeonschaub on Slack

@eval do_some_operation(::$(set), lhs, rhs) = $(Expr(op, :lhs, :rhs))

works and for things like \xor one needs to write

@eval do_some_operation(::$(set), lhs, rhs) = $(Expr(:call, op, :lhs, :rhs))

or simply $op(lhs, rhs)

1 Like