stacks-network / stacks-network/stacks-core
Explicit variant patterns for match expressions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.1k
- Forks
- 762
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 76
Description
The match expression in Clarity would benefit from supporting explicit variants for the match patterns, instead of just symbols to bind for each branch. This will also make the syntax more flexible, ready to adapt to advances like the native enum types proposed in stacks-network/reference#9.
Here is an example of explicit variant patterns to match on response type, with branches for the ok and err variants:
(match res
(ok value) (+ value 1)
(err code) code)
This replaces the current syntax:
(match res
ok-value (+ ok-value 1)
err-code err-code)
Note that in the current syntax, developers typically will use naming to signal the variant for each of the branches, but it can be obfuscated as it is the order of the branches not the name that matters. In contrast, with explicit variant patterns, the intent for each branch is apparent by default.
See also the proposed if-let construct:
https://github.com/blockstack/stacks-blockchain/issues/1403
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the linked Clarity match documentation and compare the current and proposed pattern examples in this issue. Determine the language and parser entry points that implement match expressions, then define completion as supporting explicit ok and err variant patterns while preserving branch behavior and compatibility with the existing syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100