Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some inconsistencies when using Or matching #193

Open
KristofferC opened this issue May 31, 2023 · 1 comment
Open

Some inconsistencies when using Or matching #193

KristofferC opened this issue May 31, 2023 · 1 comment

Comments

@KristofferC
Copy link
Contributor

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.

@cstjean
Copy link
Collaborator

cstjean commented Jun 15, 2023

Agreed that it's inconsistent. Not sure which way we should resolve it though.

julia> @capture(:(begin; x = 2;y=3; end), begin body_ end)
true

felt surprising to me, but at the same time I can kinda see the reasoning behind it. I'm a bit worried that if we changed that to false, we'd break people's code somewhere, and might learn the original reason for this behaviour.

So that leaves us with making

julia> @capture(:(begin; x = 2;y=3; end), begin body_ end | for i_ in iter_ forbody_ end)
false

true. Not a great fan, but it's probably safer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants