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

Coconut 2.0 pattern-matching changes #605

Closed
evhub opened this issue Oct 28, 2021 · 1 comment
Closed

Coconut 2.0 pattern-matching changes #605

evhub opened this issue Oct 28, 2021 · 1 comment

Comments

@evhub
Copy link
Owner

evhub commented Oct 28, 2021

For Coconut 2.0, there will be non-backwards-compatible changes in pattern-matching syntax. Specifically:

  • Python-style pattern-matching constructs will become the default (see Integrate Python 3.10 pattern matching #558).
    • Thus, vector(x, y) will need to be written as data vector (x, y) and
    • {"a": a, "b": b} will need to be written as {"a": a, "b": b, **{}}.
  • =<expr> will be removed and should instead be written ==<expr>.
  • x is int will be removed and should instead be written int() as x or x `isinstance` int.
  • With is no longer meaning isinstance, is <expr> will now be allowed in patterns to mean identity comparison.

A --coconut-syntax-version flag should be added to allow the old syntax to help in porting old codebases to 2.0.

@evhub
Copy link
Owner Author

evhub commented Nov 9, 2021

This has now been implemented, but it's been done in a way that I actually think will be pretty backwards-compatible, potentially obviating the need for any sort of backwards-compatibility flag. In particular:

  • =<expr> and x is int still work, they just print warnings (errors on --strict) and
  • vector(x, y) still works, since Coconut will now dynamically check to see whether vector is a data type or not to determine whether to do data matching or class matching by default.

Thus, the only real backwards-compatibility issue here is dict patterns, which will need to have **{} added to them to continue working as they previously did. Seems like it's not worth adding a flag just for that, though.

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

No branches or pull requests

1 participant