Re: fn:slice()

> Did you consider other verbs(nouns?) other than slice?

Based on these examples, I would be comfortable with the name extract() .

On Thu, Dec 3, 2020 at 2:33 AM Dave Pawson <dave.pawson@gmail.com> wrote:

> Certainly logical and consistent, and (to me) clear.
>  Did you consider other verbs(nouns?) other than slice?
>      I'd like to hear an opinion of someone with ESL?
> regards
>
> On Thu, 3 Dec 2020 at 10:27, Michael Kay <mike@saxonica.com> wrote:
> >
> > Here's my latest attempt, illustrated by example:
> >
> > Note that this (potentially) replaces existing or proposed functions as
> follows
> >
> > head(X) ===> slice(X, 1)
> > tail(X) ===> slice(X, start:=2)
> > item-at(X, N) ===> slice(X, N)
> > foot(X) ===> slice(X, -1)
> > truncate(X) ===> slice(X, end:=-2)
> > slice(X, A to B by C) ===> slice(X, start:=A, end:=B, step:=C)
> > subsequence(X, S, L) ==> slice(X, start:=S, length:=L)
> > items-before(X, P) ===> slice(X, before:=P)
> > items-after(X, P) ===> slice(X, after:=P)
> > items-from(X, P) ===> slice(X, from:=P)
> > items-until(X, P) ===> slice(X, until:=P)
> > X[position() gt P] ===> slice(X, start:=P+1)
> > X[position() = A to B] ===> slice(X, start:=A, end:=B)
> > X[last()] ===> slice(X, -1)
> > X[last()-1] ===> slice)X, -2)
> >
> > All variants return the results in their original order.
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), at:=2) returns "b".
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), at:=-1) returns "e".
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), at:=0) returns ().
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), start:=2) returns
> ("b", "c", "d", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), start:=-2) returns
> ("d", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), step:=2) returns
> ("a", "c", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), start:=2, step:=2)
> returns ("b", "d").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), end:=3) returns ("a",
> "b", "c").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), start:=2, end:=3)
> returns ("b", "c").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), start:=2, length:=3)
> returns ("b", "c", "d").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), start:=-3, length:=2)
> returns ("c", "d").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), end:=-2) returns
> ("a", "b", "c", "d").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), at:=(1, 4, 5))
> returns ("a", "d", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), at:=(5, 4, 1))
> returns ("a", "d", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), at:=(1, -1)) returns
> ("a", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), at:=(1 to 4) returns
> ("a", "b", "c", "d").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), from:=matches(?,
> "c")) returns ("c", "d", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), after:=matches(?,
> "c")) returns ("d", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), before:=matches(?,
> "c")) returns ("a", "b").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), until:=matches(?,
> "c")) returns ("a", "b", "c").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), start:=2,
> until:=matches(?, "c"))returns ("b", "c").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), from:=matches(?,
> "c"), until:=matches(?, "e")) returns ("c", "d", "e").
> >
> > The expression fn:slice(("a", "b", "c", "d", "e"), start:=2,
> from:=matches(?, "a")) returns ("b", "c", "d", "e").
>
>
>
> --
> Dave Pawson
> XSLT XSL-FO FAQ.
> Docbook FAQ.
>
>

-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Received on Thursday, 3 December 2020 15:46:54 UTC