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

@trymatch to return Some #184

Open
jariji opened this issue Feb 21, 2024 · 0 comments
Open

@trymatch to return Some #184

jariji opened this issue Feb 21, 2024 · 0 comments

Comments

@jariji
Copy link
Contributor

jariji commented Feb 21, 2024

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.

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

1 participant