Skip to content

Commit

Permalink
Merge pull request #202 from jkroso/patch-1
Browse files Browse the repository at this point in the history
Update pattern-matching.md
  • Loading branch information
cstjean committed May 9, 2024
2 parents c9f9e98 + 74d55fa commit 0daeb44
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/src/pattern-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ Another common use case is to catch symbol literals, e.g.

which will match e.g. `struct Foo ...` but not `struct Foo{V} ...`

If you want to match on quoted symbols like `:(:a)` you might look at the AST Julia
produces and expect to be able to use the type `QuoteNode` in your pattern. Hence,
you would expect the following to produce `1`:

```julia
@match :(:a) begin
s_QuoteNode => 1
s_quote => 2
end
```
However, it evaluates to `2` because MacroTools normalizes expressions before comparing
them to your pattern. And `QuoteNode` gets normalized to `quote` so to match a quoted
symbol you will need `@capture(ex, s_quote) && s.args[1] isa Symbol`

### Unions

`@capture` can also try to match the expression against one pattern or another,
Expand Down

0 comments on commit 0daeb44

Please sign in to comment.