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

922 B
Raw Permalink Blame History

Value Patterns

In AVAP, value patterns are used to match specific values. The syntax for a value pattern is:

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:

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.