Skip to content

The offset selection a lot clunkier than the MF1 one #1099

@mihnita

Description

@mihnita

These are some of the tests in the test/tests/functions/offset.json file

    {
      "src": ".local $x = {1 :offset add=1} .match $x 1 {{=1}} 2 {{=2}} * {{other}}",
      "exp": "=2"
    },
    {
      "src": ".local $x = {10 :integer} .local $y = {$x :offset subtract=6} .match $y 10 {{=10}} 4 {{=4}} * {{other}}",
      "exp": "=4"
    }

Let's take the first one and wrap it for readability:

.local $x = {1 :offset add=1}
.match $x
  1 {{=1}}
  2 {{=2}}
  * {{other}}

In MF1 the exact selection is done on the value without an an offset applied, only the keyword comparisons apply the offset.

So the result would be "=1", not "=2".

Now, one might argue that the the test matches the :offset selection as currently described in "spec/functions/number.md".

I know I explained more than once that what the MF1 behavior is.
I can try to track down if this was in the end decided by a vote and I was overruled, or it was just a case of mistake / misunderstanding.

This is the example listed in the spec/functions/number.md file, "The :offset function" section:

.input {$like_count :integer}
.local $others_count = {$like_count :offset subtract=1}
.match $like_count $others_count
0 *   {{Your post has no likes.}}
1 *   {{{$name} liked your post.}}
* one {{{$name} and {$others_count} other user liked your post.}}
* *   {{{$name} and {$others_count} other users liked your post.}}

It works with the current spec, but it is more verbose and clunkier than MF1, which requires a single selector:

{like_count, plural, offset:1
  =0    {Your post has no likes.}
  =1    {{name} liked your post.}
  one   {{name} and # other user liked your post.}
  other {{name} and # other users liked your post.}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions