macro awhen(expr, body...)
esc(quote
let it = $(expr)
if it != nothing
$(body...)
end
end
end)
end
julia> @awhen([1, 2, 3], it[2]) # workds fine
2
julia> @awhen(nothing, it[2]) # workds fine
julia> @awhen([1, 2, 3], x = 1, it[x]) # :(, failed
ERROR: unsupported or misplaced expression kw
julia> macroexpand(:@awhen([1,2,3], x = 1, it[x]))
quote # none, line 3:
let it = [1,2,3] # line 4:
if it != nothing # line 5:
x=1
it[x]
end
end
end
Have no idea how to let this worked...
Please help me, thanks.
