Suppose I am trying to write an ast transformation.
using MacroTools: postwalk
postwalk(expr) do e
r = @trymatch e begin
:($f($x)) => Some(x)
:($g($x)) => Some(x)
end
@match r begin
nothing => e
Some(x) => x
end
end
Note Some(x) is necessary because otherwise it is impossible to distinguish between "the value happened to be nothing" and "matching failed". It would be a little nicer if @trymatch did the Some(x) automatically because (1) it is convenient for users who use Some anyway and (2) it will lead users toward correct usage; currently it is too easy to accidentally forget Some which may lose information.
Suppose I am trying to write an ast transformation.
Note
Some(x)is necessary because otherwise it is impossible to distinguish between "the value happened to benothing" and "matching failed". It would be a little nicer if@trymatchdid theSome(x)automatically because (1) it is convenient for users who useSomeanyway and (2) it will lead users toward correct usage; currently it is too easy to accidentally forgetSomewhich may lose information.