assistance-engine/docs/developer.avapframework.com/chapter9_45.md

24 lines
669 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 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.
Heres 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.