f(x) = @cond begin
x < 0 => error("please provide a positive number")
x < 5 => :smaller
x == 5 => :equal
x > 5 => :bigger
end
f(-5) # error!!
f(3) # :smaller
f(5) # :equal
f(7) # :bigger
Cond brings in a simple macro which can help the readability of nested conditionals. Consider how you could write the expression above using traditional if statements.
f(x) =
if x < 0
error("please provide a positive number")
elseif x < 5
:smaller
elseif x == 5
:equal
elseif x > 5
:bigger
else
error("no match")
end
Another alternative is to use ternary expression
f(x) =
x < 0 ? error("please provide a positive number") :
x < 5 ? :smaller :
x == 5 ? :equal :
x > 5 ? :bigger :
error("no match")