Re: fn:slice()

Could you, please, provide the arity of each proposed function? It isn't
quite clear.

I would generally prefer to have as few keyword parameters as possible.
That is, if we only can have 2-3 positional arguments, this feels better
than having 2+ keyword arguments, whose names one needs to memorize.

Let us accept this general principle:
*No magic words! No magic spells! It is just logic!*


On Fri, Dec 4, 2020 at 2:15 AM Michael Kay <mike@saxonica.com> wrote:

> Which do you prefer?
>
>
Obviously: a swiss-army knife...  What to say more?  :(

> Option A
>
> A single (swiss-army-knife) slice() function as proposed yesterday
>



*Would be the best, especially if most/all keywords are removed *. This
would be the most logical, thus least demanding on memorizing and learning:


>
> Option B
>
> Three functions:
>
>
This is OK

> * fn:items-at($seq, xs:integer+) returning the items at the given positions
>
>

Prefer two functions:
 fn:slice($seq, $start, length? )
 fn:slice($seq, $start, $end,  step? )

> * fn:slice($seq, start?, step?,  (end | length)? ) accepting some
> combination of start, end, length, and step, each supplied as an integer
>




 Not sure about this. The name "range" is quite static, but the described
behavior is dynamic. Maybe use a name like: "subsequence-lifted" and avoid
keyword args at all:
subsequence-lifted($seq, $signal-start as function(item()) as xs:integer)
as item()*
subsequence-lifted($seq, $signal-start as function(item()) as xs:integer,
$signal-end as function(item()) as xs:integer ) as item()*

> * fn:range($seq, (before | until)? (after | from)?) accepting predicates
> for the start and/or end of the selected range
>
> This retains most of the useful combinations, but each of the functions is
> much simpler. (I've used an informal notation to indicate which
> combinations of parameters are allowed). Negative positions allowed for
> items-at, start, and end.
>
>

Also not too-bad, but the magic words all need memorizing, and are not
natural for non-native speakers of English

> Option C
>
> Two functions:
>
> fn:slice($seq, $positions as integer+)
>
> where $positions might be (3), (-1), (1 to 5) or ( 1 to 5 by 2).
>
> fn:range($seq, (before | until)? (after | from)?) accepting predicates for
> the start and/or end of the selected range
>

Thanks,
Dimitre

On Fri, Dec 4, 2020 at 2:15 AM Michael Kay <mike@saxonica.com> wrote:

> Which do you prefer?
>
> Option A
>
> A single (swiss-army-knife) slice() function as proposed yesterday
>
> Option B
>
> Three functions:
>
> * fn:items-at($seq, xs:integer+) returning the items at the given positions
>
> * fn:slice($seq, start?, step?,  (end | length)? ) accepting some
> combination of start, end, length, and step, each supplied as an integer
>
> * fn:range($seq, (before | until)? (after | from)?) accepting predicates
> for the start and/or end of the selected range
>
> This retains most of the useful combinations, but each of the functions is
> much simpler. (I've used an informal notation to indicate which
> combinations of parameters are allowed). Negative positions allowed for
> items-at, start, and end.
>
>
Option C
>
> Two functions:
>
> fn:slice($seq, $positions as integer+)
>
> where $positions might be (3), (-1), (1 to 5) or ( 1 to 5 by 2).
>
> fn:range($seq, (before | until)? (after | from)?) accepting predicates for
> the start and/or end of the selected range
>
>
> Michael Kay
> Saxonica
>
> On 4 Dec 2020, at 03:52, Mukul Gandhi <gandhi.mukul@gmail.com> wrote:
>
> On Fri, Dec 4, 2020 at 8:04 AM Dimitre Novatchev <dnovatchev@gmail.com>
> wrote:
>
>> While this function is obviously very powerful, its complexity affects
>> the learning and confidence of use.
>>
>> This leads to not-confident / hesitant / unhappy developers.
>>
>
> I agree to above mentioned concerns.
>
> But +1 to introduction of fn:slice() function to XPath/XSLT.
>
>
>
> --
> Regards,
> Mukul Gandhi
>
>
>

Received on Friday, 4 December 2020 15:49:14 UTC