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

30 lines
922 B
Markdown
Raw Permalink 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.

## Value Patterns
In AVAP, value patterns are used to match specific values. The syntax for a value pattern is:
```javascript
value_pattern ::= attr
```
Value patterns only succeed if the subject's value matches the specified value. They are useful when you want to perform actions based on an exact value.
Heres how you might use value patterns in AVAP:
```javascript
match value:
case 42:
print("Matched the value 42")
case "hello":
print("Matched the string 'hello'")
case _:
print("Matched something else")
```
In this example:
* `case 42:` matches the value 42 specifically.
* `case "hello":` matches the string "hello" specifically.
* `case _:` matches any other value not covered by the previous cases.
Value patterns are ideal for scenarios where you need to check for specific values and respond accordingly. They provide precise control over the matching process.