From 7b7a07c8dfa8bb2f6e11536edeb929ff701ac4e5 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Thu, 3 Apr 2025 07:33:16 +0000 Subject: [PATCH] Update Implementations and Type Patterns --- Implementations-and-Type-Patterns.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Implementations-and-Type-Patterns.md b/Implementations-and-Type-Patterns.md index 9f7097f..0498f1b 100644 --- a/Implementations-and-Type-Patterns.md +++ b/Implementations-and-Type-Patterns.md @@ -10,7 +10,7 @@ The currently supported and/or planned Type Patterns are as follows: * Any generic type may be considered a pattern that matches a single-element sequence of any instantiation of itself or subtype of an instantiation of itself. * The built-in pattern `Any` (note it is disallowed to have a type named `Any`) matches any single-element sequence of types. * If `P1`, `P2`, ..., `Pn` are patterns, then the sequence of patterns `[P1, P2, ..., Pn]` matches any sequence of argument types that can be partitioned into n subsequences, the first of which matches P1, the second matches P2, and so on, up to the final subsequence matching Pn. Note that when the actual arguments that match such a sequence of patterns is conveyed to an associated behavior (see below), they are always transmitted as exactly n arguments -- the portions of the actual argument sequence each of the patterns matched. Note that generally, single-argument portions are passed simply as the single corresponding value, except as noted below, whereas 0-length and ≥2-length portions are always passed as ordinary arrays of the corresponding values. -* If `P` is a pattern, then `Multiple(P)` is a pattern that matches any number of repeats of matches to P, including zero. For convenience, a match to `Multiple(P)` is always conveyed to an associated behavior as an Array of the underlying matches, even if there is only one match. +* If `P` is a pattern, then `Multiple(P)` is a pattern that matches any number of repeats of matches to P, including zero. For convenience, a match to `Multiple(P)` is always conveyed to an associated behavior as an Array of the underlying matches, even if there is only one match. Note that `Multiple` patterns match greedily, and there is no backtracking. For example, in the pattern `[Multiple(Number), Multiple(Number)]`, the second match would always be empty, and the patterns `[Multiple(Number), Number]` can never match anything, as the matching of the first pattern would use up all initial Number arguments, so the next remaining argument, if any, would definitely not be a number. * If `P` is a pattern, then `Optional(P)` is a pattern that will match 0 or 1 occurrences of matches to P. As with `Multiple(P)`, a match to `Optional(P)` will always be conveyed as an ordinary Array of length 1 or 0. This convention is necessary because any value that could be used as a "sentinel" that no match to P occurred might, for some pattern P, also constitute an ("unboxed") single match to P. E.g., if `[]` were used for no match, then receiving an argument `[]` from a match to `Optional(Array(Boolean))` would be ambiguous between no match and matching an actual argument of `[]`. Some consequences of these definitions: