Re: [xsl] Functional programming in XSLT (revised)

Subject: Re: [xsl] Functional programming in XSLT (revised)
From: Alexey Gokhberg <alexei@xxxxxxxxxx>
Date: Fri, 16 Mar 2001 14:19:40 +0100
Hello, David

David Rosenborg wrote:
> 
> > <fxsl:function name="qname">
> >   <!-- parameters -->
> >   <!-- local variables and functions -->
> >   <fxsl:return ...>
> > </fxsl:function>
> >
> 
> I think you are working in all the right directions. However, the function definition part looks
> very close to v0.2 of FXPath (http://www.pantor.com/fxpath02/). And I think there
> were good reasons for the changes I made in v0.3 (http://www.pantor.com/fxpath/). Since you have
> already decided to add new syntax to XPath, why not go all the way as in FXPath? In fact, why not
> try and base your design on FXPath?
> 
> Simple outline:
> 
> * Allow fx:define and fx:template-function where you allow fxsl:function, with the same scoping rules.
> * Add fx:call and fx:function extension functions (fx:function similar to fxsl:lambda, the word lambda is nice
>   for historical reasons but I think function is more in line with XPath terminology)
> * Add the non terminal FunctionDefinition to the Expr production.
> * Maybe remove the special 'reduce' syntax. It can now be implemented as a function, though
>   I would personally keep it for convenience.
> 

Sure, reviewing the recent FXPath specification could provide important
ideas for the future FXSLT research. I will follow, however, the initial
approach, voting for extending XSLT rather than XPath.

I like the word "lambda". It is a signature of FXSLT and I plan to
retain it. (I was quite unhappy when I was forced to demote
"fxsl:lambda" from the XSLT instruction down to the XPath function.)


> > 3. Conditional operator in XPath
> > --------------------------------
> >
> > The conditional operator is added to XPath. The proposed syntax is
> >
> > if TEST then CONSEQUENT else ATERNATE
> >
> > where "if", "then" and "else" are "reserved words", and "TEST",
> > "CONSEQUENT" and "ALTERNATE" are XPath expressions.
> >
> 
> You might consider requiring parenthesis around the consequent and alternate
> expr as in FXPath. The reason is to get a more intuitive behaviour
> in situations where you want to select the root node in the consequent like:
> 
> if $test then / else /something
> 
> would become
> 
> if ($test) then (/) else (/something)
> 
> also, this kind of syntax follows the pattern of other special forms/keywords in XPath.
> 

I would retain the current syntax for if/then/else. The stylesheet
author must use parentheses properly (this is the required skill for
every functional programmer).

More on these subject please find in my recent reply to Jeni.

> > 4. Total cost
> > -------------
> >
> > Following is the total cost of this proposal (in terms of added
> > features):
> >
> > 1. Extension XSLT instructions:   1
> > 2. Other XSLT extension elements: 1
> > 3. Extension XPath functions:     2
> > 4. Extension XPath data types:    1
> > 5. Extensions in XPath syntax:    1
> > -----------------------------------
> > Total of added features:          6
> 
> Well, this cost doesn't say that much from an implementors point of view. Introducing locally scoped
> functions and closures into current XSLT implementations is a rather intrusive thing. I'm not saying it's
> particulary hard, just that it cannot be layered nicely on top of them.
> 

Being an XSLT implementor myself, I see no particular difficulties for
building the proposed FXSLT extensions on the top of an average XSLT
processor architecture. 

Indeed, much more critical for the functional programming is
availability of an efficient implementation for the optimizing XPath 1.0
processor, providing a special treatment for some important XPath
constructions like $set[position() &gt; 1] or some special kinds of
node-set unions. (Well, FXSLT will add a specific requirement for
dealing with tail recursion). However, an efficient XPath implementation
is must for any modern XSLT processor, and most XSLT vendors had
resolved this issue already or will do it in the near future anyway.

Kind regards,

Alexey

----------------
Alexey Gokhberg
Unicorn Enterprises SA
http://www.unicorn-enterprises.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread