30 lines
922 B
Markdown
30 lines
922 B
Markdown
## 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.
|
||
|
||
Here’s 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.
|