Re: Range Expressions

I think the most natural syntax would be to interpret the 'direction' of the step by the order of arguments; for me that is implicit by use of the word 'to': I would (naturally) expect:

 5 to 1 by 1 = (5, 4, 3, 2, 1)
 1 to 5 by 1 = (1, 2, 3, 4, 5)
 1 to -5 by 1 = (1, 0, -1, -2, -3, -4, -5)
 1 to 5 by -1 = error

So that the 'by' argument is always positive.

Tom

_________________
Tomos Hillman
eXpertML Ltd
+44 7793 242058
On 7 Dec 2020, 14:19 +0000, Christian Grün <cg@basex.org>, wrote:
> I showed the proposed syntax (1 to 5 by -1) to a non-X(Path|SLT|Query)
> developer, and the immediate response was:
>
> You must be wrong, it’s surely supposed to be: 5 to 1 by -1
>
> I guess it’s too late to always start counting with the smaller value,
> or to even allow "5 to 1" for reverse counts. Michael initially
> proposed to place "by" ahead of "to" [1]…
>
> 5 by -1 to 1
>
> …and I wonder if it’s not the better choice?
>
> [1] https://github.com/expath/xpath-ng/issues/22
> ____________________________________
>
> On Tue, Dec 1, 2020 at 10:02 PM Dimitre Novatchev <dnovatchev@gmail.com> wrote:
> >
> > > Apart from anything else, it loses the idioms in the current language that rely on a range being a sequence of integers,
> > > enabling familiar constructs such as x[position() = 1 to 10].
> >
> > Well, there is nothing wrong with series of time periods in a total time range.
> >
> > Maybe we can have a lifted overload of range, providing a function that, when applied on the provided as integers start, end and step, will produce the actual start, end and step for the actual range:
> >
> > range($startBase as xs:integer,
> > $endBase as xs:integer,
> > $stepBase as xs:integer,
> > $provider as function(xs:integer) as item() )
> > as item()*
> >
> > So, the provider() or better name, will convert the integers to whatever typed-data we need.
> >
> > Thanks,
> > Dimitre
>

Received on Monday, 7 December 2020 14:42:44 UTC