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

Update pattern-matching.md #202

Merged
merged 3 commits into from
May 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/src/pattern-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ 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 quoted symbols and happen to know that Julia's parser parses
them as `QuoteNode` then you might try `@capture(ex, s_QuoteNode)` and discover that
it never matches. This is because expressions are normalized before being matched
against the pattern. And `QuoteNode` get normalized to `quote` so to match a quoted
jkroso marked this conversation as resolved.
Show resolved Hide resolved
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
Loading