|
Subject: Re: [xsl] XSLT 2.0 courses? From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 21 Sep 2020 19:51:48 -0000 |
On Mon, 2020-09-21 at 19:18 +0000, Graydon graydon@xxxxxxxxx wrote:
> On Mon, Sep 21, 2020 at 07:06:21PM -0000, Dimitre Novatchev
> dnovatchev@xxxxxxxxxx scripsit:
> > > B filter($sequence,$function) => head()
> >
> > Is there any guarantee that the evaluation of filter() will stop as
> > soon as
> > an initial item is produced?
>
> I wouldn't think there would be, given that filter() in general is
> specified to filter the whole sequence.
In some cases the expression can be rewritten so that filter() is
replaced by $function(head($sequence)); you can only do this if you
know that $function() won't return an empty sequence though, and
$sequence is known at compile time. BaseX does some rewrites in this
vein, although i don't know if it can ever do this one. Oh kinda:
filter( (1 to 1000), function($input as xs:integer) { $input * 2 } )
=> head()
Optimized Query:
head((1 to 1000)[((. mod 2) = 0)])
Similarly, head( (1 to 10000) )
is optimized to
<QueryPlan compiled="true" updating="false">
<Int type="xs:integer" size="1">1</Int>
</QueryPlan>
I've used languages that had infinite (OK, uunbounded) sequences as
first class objects, with lazy evaluation, which can be a very natural
way to think about cases like this. But we don't have them :)
It's always hard to know how much optimizing to do in what is
essentially an interpreter - at somep point you can spend so long
optimizing that you end up slower. But if the optimized queries can be
reused in production it's another matter...mmodulo errors!
--
Liam Quin,B https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: B http://www.fromoldbooks.org
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] XSLT 2.0 courses?, Dimitre Novatchev dn | Thread | Re: [xsl] XSLT 2.0 courses?, Peter Flynn peter@xx |
| Re: [xsl] XSLT 2.0 courses?, Dimitre Novatchev dn | Date | [xsl] Are xsl:accumulator-rules exc, Christophe Marchand |
| Month |