24 lines
669 B
Markdown
24 lines
669 B
Markdown
## Capture Patterns
|
||
|
||
In AVAP, capture patterns are used to bind the subject's value to a name. The syntax for a capture pattern is:
|
||
|
||
```javascript
|
||
capture_pattern ::= NAME
|
||
```
|
||
|
||
Capture patterns always succeed and bind the value of the subject to the specified name.
|
||
|
||
Here’s how you might use capture patterns in AVAP:
|
||
|
||
```javascript
|
||
match value:
|
||
case x:
|
||
print(f"Captured value: x")
|
||
```
|
||
|
||
In this example:
|
||
|
||
* `case x:` captures whatever value is in `value` and binds it to the name `x` . The pattern always succeeds.
|
||
|
||
Capture patterns are useful when you want to extract and use the value of the subject within your code, regardless of what that value is.
|