[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Functional Programming: How do I convert an xsl:f

Subject: Re: Functional Programming: How do I convert an xsl:for-each loop into a functional style?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 21 Jan 2010 06:16:00 -0800
Re:  Functional Programming: How do I convert an  xsl:f
> My understanding is that a litmus test for whether a program is written in a
functional style is whether it can be executed in any order.

This is a large exaggeration. If there are functions foo() and bar(),
then in the expression:

   foo(bar(x))

foo() cannot be evaluated before bar(x) has been evaluated.


In fact, there are many examples of expressions that require quite
strict sequential evaluation. This demonstrates the power of FP that
an expression can be used to specify both no-sequential and (quite)
sequential processing.

Finally, the proposed solution of the partial sums problem is very
inefficient -- O(N^2)). For a solution with linear complexity use the
f:scanl() function of FXSL.

--
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
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play



On Thu, Jan 21, 2010 at 4:38 AM, Costello, Roger L. <costello@xxxxxxxxx>
wrote:
> Hi Folks,
>
> My question is about writing XSLT in a functional programming style.
>
> My understanding is that a litmus test for whether a program is written in a
functional style is whether it can be executed in any order.
>
> Consider this problem: convert a sequence of N numbers into a cumulative
sequence, in which each number is the sum of the previous numbers.
>
> Here is a loop that solves the problem:
>
> <xsl:for-each select="Number">
> B  B  B <xsl:value-of select="sum((., preceding-sibling::Number))" />
> </xsl:for-each>
>
> Can this code be executed in any order?
>
> Suppose the loop is unraveled into a series of <xsl:value-of> statements. If
those statements are evaluated in arbitrary order then the output would not be
in the desired sequence. B Thus, I conclude, this loop is not written in a
functional style. Do you agree?
>
> How would the problem be solved in a functional style?
>
> /Roger

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.