Looking for good macro examples

You can, just put the whole quoted expression in esc.

module MM
foo(y) = println("foo was called with $y")
macro foo_fun(name, expr)
    x = gensym()
    esc(quote
        function $name($x)
            $MM.foo($x)
            $expr
        end
    end)
end
end

using MM: @foo_fun
@foo_fun bobby 45
bobby(4)

I haven’t written any macro-writing-macro yet, I’m not sure how that goes. Julia’s quote is a backquote, but you can get normal-quote by writing

y = :u
quote
    $(Expr(:quote, y))
end

It’s equivalent to ', in Common Lisp.

2 Likes