Re: [xsl] Need help with XSLT tokenize

Subject: Re: [xsl] Need help with XSLT tokenize
From: "Norman Tovey-Walsh ndw@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 13 Aug 2020 11:02:17 -0000
> What about XSLT 3's xsl:iterate? Isn't that, with its parameters that
> can change on each iteration step, close to a procedural, sequential
> loop?

Yes and no. Yes, it does kind of behave like a loop, and if you use it
to bloop overb a sequence, thatbs one way to look at it. But no, itbs
not really like a for-loop in C or Python or your favorite imperative
language.

Functional languages often have things that are bloop likeb: fold-left
and fold-right[1], for example (which XPath has), and more generally
recursive functions that can be implemented as loops by the compiler if
you structure them so that theybre tail recursive[2].

The xsl:iterate instruction is, from one perspective, a fold with a
syntax that makes it easier to understand. Or, as I described it
recently, a recursive function with guard rails (which is probably not
technically exactly right, but I claim poetic license).

Confession: I came relatively late to functional programming and Ibve
probably only used fold-left about a dozen times. Hard core functional
programmers will probably find that surprising as theybre really useful.
But if you donbt think in functional terms, they can really seem
pointless and confusing. My first actual use of fold-left happened
because I was tasked to maintain a bit of XQuery code where the previous
implementor had used an extension to mutate a variable in a loop. I
*knew* that it must be possible to do it without that horrible hack, and
I stared at until fold-left occurred to me *and* I worked out how to
make it work. About ten of the dozen times Ibve used fold left were
probably to solve exactly the same problem elsewhere in that code base.

                                        Be seeing you,
                                          norm

[1] https://en.wikipedia.org/wiki/Fold_(higher-order_function)
[2] https://en.wikipedia.org/wiki/Tail_call

--
Norman Tovey-Walsh <ndw@xxxxxxxxxx>
https://nwalsh.com/

> As a general rule, the most successful man in life is the man who has
> the best information.--Benjamin Disraeli

[demime 1.01d removed an attachment of type application/pgp-signature which had a name of signature.asc]

Current Thread