Re: Range Expressions

This feels to me like a step too far. If we had an object-oriented language with strong infrastructure for new types like this then it might be the right thing to do, but at present it doesn't blend in well. 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].

Michael Kay
Saxonica 

> On 1 Dec 2020, at 16:50, Dimitre Novatchev <dnovatchev@gmail.com> wrote:
> 
> I would rather prefer this to be a system-provided  record  type. Name it   range
> 
> record(start? xs:integer, end? xs:integer, step? xs:integer)
> 
> Then one can provide a set of functions defined on the range type (and using the arrow operator comes handy here) 
>  
>      range?start
>   range?end
>   range?step
> 
>   sequence($r as range) as xs:integer*
>   size($r as range) as xs:integer
>   index-at($r as range, $pos as xs:integer) as xs:integer
>   reverse($r as range) as range
> 
> Thanks,
> Dimitre
> 
> On Mon, Nov 30, 2020 at 6:05 AM Michael Kay <mike@saxonica.com <mailto:mike@saxonica.com>> wrote:
> Someone, I forget who, gave feedback suggesting making "by" a binary operator so
> 
> 1 to 10 by 2 means ((1 to 10) by 2) i.e. 1, 3, 5, 7, 9 
> 1 to 10 by -1 gives 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
> ("A", "B", "C", "D") by 2 gives ("A", "C")
> ("A", "B", "C", "D") by -2 gives ("D", "B")
> 
> I've adopted this suggestion in my latest draft.
> 
> Michael Kay
> Saxonica
> 

Received on Tuesday, 1 December 2020 19:31:48 UTC