You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The design alternative [Match on variables instead of expressions](#match-on-variables-instead-of-expressions)
164
+
described below is selected.
163
165
164
166
## Alternatives Considered
165
167
166
-
_What other solutions are available?_
167
-
_How do they compare against the requirements?_
168
-
_What other properties they have?_
169
-
170
168
### Do nothing
171
169
172
170
In this alternative, selectors are independent of declarations.
@@ -422,3 +420,69 @@ and a data model error otherwise.
422
420
Removes some self-documentation from the pattern.
423
421
- Requires the pattern to change if the selectors are modified.
424
422
- Limits number of referenceable selectors to 10 (in the current form)
423
+
424
+
### Hybrid approach: Match may mutate, no duplicates
425
+
426
+
In this alternative, in a `.match` statement:
427
+
428
+
1. variables are mutated by their annotation
429
+
2. no variable can be the operand in two selectors
430
+
431
+
This keeps most messages more concise, producing the expected results in Example 1.
432
+
433
+
#### Example 1
434
+
435
+
```
436
+
.match {$count :integer}
437
+
one {{You have {$count} whole apple.}}
438
+
* {{You have {$count} whole apples.}}
439
+
```
440
+
is precisely equivalent to:
441
+
442
+
#### Example 2
443
+
```
444
+
.local $count2 = {$count :integer}
445
+
.match {$count2}
446
+
one {{You have {$count2} whole apple.}}
447
+
* {{You have {$count2} whole apples.}}
448
+
```
449
+
450
+
This avoids the serious problems with mismatched selection and formats
451
+
as in Example 1 under "Do Nothing", whereby the input of `count = 1.2`,
452
+
results the malformed "You have 1.2 whole apple."
453
+
454
+
Due to clause 2, this requires users to declare any selector using a `.input` or `.local` declaration
455
+
before writing the `.match`. That is, the following is illegal.
456
+
457
+
#### Example 3
458
+
```
459
+
.match {$count <anything>}{$count <anything>}
460
+
```
461
+
It would need to be rewritten as something along the lines of:
462
+
463
+
#### Example 4
464
+
```
465
+
.local $count3 = {$count}
466
+
.match {$count <anything1>}{$count3 <anything2>}
467
+
```
468
+
Notes:
469
+
- The number of times the same variable is used twice in a match (or the older Select) is vanishingly small. Since it is an error — and the advice to fix is easy — that will prevent misbehavior.
470
+
- There would be no change to the ABNF; but there would be an additional constraint in the spec, and relaxation of immutability within the .match statement.
471
+
472
+
**Pros**
473
+
- No new syntax is required
474
+
- Preserves immutability before and after the .match statement
475
+
- Avoids the serious problem of mismatch of selector and format of option "Do Nothing"
476
+
- Avoids the extra syntax of option "Allow both local and input declarative selectors with immutability"
477
+
- Avoids the problem of multiple variables in "Allow immutable input declarative selectors"
478
+
- Is much more consise than "Match on variables instead of expressions", since it doesn't require a .local or .input for every variable with options
479
+
- Avoids the readability issues with "Provide a #-like Feature"
480
+
481
+
**Cons**
482
+
- Complexity: `.match` means more than one thing
483
+
- Complexity: `.match` implicitly creates a new lexical scope
484
+
- Violates immutability that we've established everywhere else
485
+
- Requires additional `.local` declarations in cases where a variable would occur twice
486
+
such as `.match {$date :date option=monthOnly} {$date :date option=full}`
0 commit comments