Typically, if @capture(expr, match_1) matches you would expect @capture(expr, match_1 | match_2) to always also match. This is however not the case. For example:
julia> @capture(:(begin; x = 2;y=3; end), begin body_ end)
true
julia> body
quote
#= REPL[2]:1 =#
x = 2
#= REPL[2]:1 =#
y = 3
end
matches, but the following
julia> @capture(:(begin; x = 2;y=3; end), begin body_ end | for i_ in iter_ forbody_ end)
false
does not. In addition, it the expression in the block only contains one expression, there will be a match:
julia> @capture(:(begin; x = 2; end), begin body_ end | for i_ in iter_ forbody_ end)
true
julia> body
:(x = 2)
This feels inconsistent to me.
Typically, if
@capture(expr, match_1)matches you would expect@capture(expr, match_1 | match_2)to always also match. This is however not the case. For example:matches, but the following
does not. In addition, it the expression in the block only contains one expression, there will be a match:
This feels inconsistent to me.