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
Copy file name to clipboardExpand all lines: exploration/selection-declaration.md
+66Lines changed: 66 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -356,3 +356,69 @@ and a data model error otherwise.
356
356
Removes some self-documentation from the pattern.
357
357
- Requires the pattern to change if the selectors are modified.
358
358
- Limits number of referenceable selectors to 10 (in the current form)
359
+
360
+
### Hybrid approach: Match may mutate, no duplicates
361
+
362
+
In this alternative, in a `.match` statement:
363
+
364
+
1. variables are mutated by their annotation
365
+
2. no variable can be the operand in two selectors
366
+
367
+
This keeps most messages more concise, producing the expected results in Example 1.
368
+
369
+
#### Example 1
370
+
371
+
```
372
+
.match {$count :integer}
373
+
one {{You have {$count} whole apple.}}
374
+
* {{You have {$count} whole apples.}}
375
+
```
376
+
is precisely equivalent to:
377
+
378
+
#### Example 2
379
+
```
380
+
.local $count2 = {$count :integer}
381
+
.match {$count2}
382
+
one {{You have {$count2} whole apple.}}
383
+
* {{You have {$count2} whole apples.}}
384
+
```
385
+
386
+
This avoids the serious problems with mismatched selection and formats
387
+
as in Example 1 under "Do Nothing", whereby the input of `count = 1.2`,
388
+
results the malformed "You have 1.2 whole apple."
389
+
390
+
Due to clause 2, this requires users to declare any selector using a `.input` or `.local` declaration
391
+
before writing the `.match`. That is, the following is illegal.
392
+
393
+
#### Example 3
394
+
```
395
+
.match {$count <anything>}{$count <anything>}
396
+
```
397
+
It would need to be rewritten as something along the lines of:
398
+
399
+
#### Example 4
400
+
```
401
+
.local $count3 = {$count}
402
+
.match {$count <anything1>}{$count3 <anything2>}
403
+
```
404
+
Notes:
405
+
- 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.
406
+
- 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.
407
+
408
+
**Pros**
409
+
- No new syntax is required
410
+
- Preserves immutability before and after the .match statement
411
+
- Avoids the serious problem of mismatch of selector and format of option "Do Nothing"
412
+
- Avoids the extra syntax of option "Allow both local and input declarative selectors with immutability"
413
+
- Avoids the problem of multiple variables in "Allow immutable input declarative selectors"
414
+
- 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
415
+
- Avoids the readability issues with "Provide a #-like Feature"
416
+
417
+
**Cons**
418
+
- Complexity: `.match` means more than one thing
419
+
- Complexity: `.match` implicitly creates a new lexical scope
420
+
- Violates immutability that we've established everywhere else
421
+
- Requires additional `.local` declarations in cases where a variable would occur twice
422
+
such as `.match {$date :date option=monthOnly} {$date :date option=full}`
0 commit comments