I came across some online posts about implementing short-circuiting logical operators as macros in Lisp, and I’m wondering how to do the same in Julia. I’m trying to write a vararg macro @or such that
@or expr1 expr2 expr3 expr4
expands into
if expr1
true
else
@or expr2 expr3 expr4
end
The recursion should end when there is only one argument, i.e.
@or expr1
should expand into simply expr1.
I made some attempts but got confused about how to interpolate vararg tuples in quote expressions. Any ideas?
Thanks, but I was actually trying to avoid the built-in || operator and re-implement it using only the if-else clause, just for fun, following this Stack Overflow Post in Lisp.
That works! A little glitch is that I tried to add esc to your args[2:end] but that breaks the interpolation. I’ll be very interested if someone knows how to do this.