Re: fn:foot, fn:truncate, fn:item-at

Hi,

>
> slice($seq, -1)  to get the last item
>
> slice($seq, 1 to count($seq)-1) to get all but the last
>
> …and if we cannot use a function, we already have $seq[position() < 
> count($seq)].


Have we forgotten about the last() function? It can do these things 
rather simple and is also shorter:

$seq[last()]

$seq[position() < last()]

Elsewhere I had proposed to allow sequences of numbers in filter 
expressions, then one could also write even shorter $seq[1 to last() - 1]

Or one could introduce an "until" operator, with (a until b) := (a to (b 
- 1)), so it becomes $seq[1 until last()]

> it may just be consistent
> to add fn:foot, too

foot does not sound good

Look at this lizard 🦎:
OpenMoji 12.2

First comes the head, then two feet and then the tail.

So foot would be the second item in the sequence not the last

One could introduce a new last function last#1, with last($seq) := 
$seq[last()]


Bye,
Benito
On 02.12.20 13:30, Christian Grün wrote:
> Thanks for the hint. I completely overlooked this new function.
>
> I’ve probably become used too much to the semantics of XPath, so I was
> surprised to see negative indexes as indicators for reverse lookups. I
> cannot remember any other functions/operators in the X domain that
> does something similar, and applying any combination with fn:reverse
> would have been my intuitive choice. On the other hand, it may just be
> my old habits, and the slice function may be well-known enough in the
> Python or JavaScript community not to cause too much confusion. It’s
> definitely better than expanding on the behavior of fn:subsequence for
> negative integers, or even doubles.
>
> If I could choose, I would be happy to see at least fn:truncate added
> to the new spec, as the argument needs to be referenced twice with
> slice. So we can’t write…
>
>    (1 to 10) => fn:slice(1 to ...)
>
> …and if we cannot use a function, we already have $seq[position() <
> count($seq)]. Next, if we add fn:truncate, it may just be consistent
> to add fn:foot, too ;)
> ____________________________________
>
> On Wed, Dec 2, 2020 at 12:02 PM Michael Kay <mike@saxonica.com> wrote:
>> The latest version allows
>>
>> slice($seq, -1)  to get the last item
>>
>> slice($seq, $N) to get the Nth item
>>
>> slice($seq, 1 to count($seq)-1) to get all but the last
>>
>> and I thought that was probably good enough to make the individual functions unnecessary.
>>
>> Would you agree?
>>
>> Michael Kay
>> Saxonica
>>
>> On 2 Dec 2020, at 10:30, Christian Grün <cg@basex.org> wrote:
>>
>> Hi Michael,
>>
>> In your first public XQFO proposal [1], I have found seen three
>> functions (fn:foot, fn:truncate, fn:item-at) that have not made it
>> into the latest specification documents. Are you still working on it,
>> or did you deliberately decide not to include them in the new draft?
>>
>> Thanks,
>> Christian
>>
>> [1] https://www.saxonica.com/qt4specs/FO/Overview-diff.html
>>
>>

Received on Wednesday, 2 December 2020 14:04:51 UTC