Skip to content

Commit

Permalink
Add hybrid option to selection-declaration.md (#870)
Browse files Browse the repository at this point in the history
* Add hybrid option to selection-declaration.md

* Update selection-declaration.md

fixed glitch in original edit

* Update selection-declaration.md

* Apply suggestions from code review

Fixing typos

Co-authored-by: Addison Phillips <[email protected]>

* Update selection-declaration.md

* Update exploration/selection-declaration.md

Co-authored-by: Eemeli Aro <[email protected]>

* Update exploration/selection-declaration.md

Co-authored-by: Eemeli Aro <[email protected]>

* Update exploration/selection-declaration.md

Co-authored-by: Eemeli Aro <[email protected]>

---------

Co-authored-by: Addison Phillips <[email protected]>
Co-authored-by: Eemeli Aro <[email protected]>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 86c261a commit c0adddd
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions exploration/selection-declaration.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,69 @@ and a data model error otherwise.
Removes some self-documentation from the pattern.
- Requires the pattern to change if the selectors are modified.
- Limits number of referenceable selectors to 10 (in the current form)

### Hybrid approach: Match may mutate, no duplicates

In this alternative, in a `.match` statement:

1. variables are mutated by their annotation
2. no variable can be the operand in two selectors

This keeps most messages more concise, producing the expected results in Example 1.

#### Example 1

```
.match {$count :integer}
one {{You have {$count} whole apple.}}
* {{You have {$count} whole apples.}}
```
is precisely equivalent to:

#### Example 2
```
.local $count2 = {$count :integer}
.match {$count2}
one {{You have {$count2} whole apple.}}
* {{You have {$count2} whole apples.}}
```

This avoids the serious problems with mismatched selection and formats
as in Example 1 under "Do Nothing", whereby the input of `count = 1.2`,
results the malformed "You have 1.2 whole apple."

Due to clause 2, this requires users to declare any selector using a `.input` or `.local` declaration
before writing the `.match`. That is, the following is illegal.

#### Example 3
```
.match {$count <anything>}{$count <anything>}
```
It would need to be rewritten as something along the lines of:

#### Example 4
```
.local $count3 = {$count}
.match {$count <anything1>}{$count3 <anything2>}
```
Notes:
- 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.
- 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.

**Pros**
- No new syntax is required
- Preserves immutability before and after the .match statement
- Avoids the serious problem of mismatch of selector and format of option "Do Nothing"
- Avoids the extra syntax of option "Allow both local and input declarative selectors with immutability"
- Avoids the problem of multiple variables in "Allow immutable input declarative selectors"
- 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
- Avoids the readability issues with "Provide a #-like Feature"

**Cons**
- Complexity: `.match` means more than one thing
- Complexity: `.match` implicitly creates a new lexical scope
- Violates immutability that we've established everywhere else
- Requires additional `.local` declarations in cases where a variable would occur twice
such as `.match {$date :date option=monthOnly} {$date :date option=full}`


0 comments on commit c0adddd

Please sign in to comment.