Re: [xsl] Re: . in for

Subject: Re: [xsl] Re: . in for
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sun, 6 Jan 2002 00:34:17 -0800 (PST)
--- Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> wrote:

[snip]

> 
>   $coordinates -> (. * 2)
>                -> if (position() mod 2) then . + 50 else .
> 

Hi Jeni,

Some additional thoughts. 

1. 'mapping operator' must mean "a map function, which is used in an infix
notation".

So instead of writing:

 map fun list

we now write:

 list `map` fun      (let's ignore that this must be the other way around).

However, the above defined mapping operator stil operates with ***any function***
defined on lists.

At the same time the mapping operator as you define it will operate only on valid
XPath expressions. This is quite limited compared to the full mapping operator,
therefore it would be best if the name of the 'limited mapping operator' properly
reflected this difference in scope.

2. The example you provide of "piping" is actually a functional composition of two
map functions. It can be re-written like this:


   (map (if (position() mod 2) then . + 50 else .)) ¡Ñ  (map (. * 2)) $coordinates 

Here I use the special symbol &#x2299; for the functional composition operator.

So, the piping can be expressed as:

     (map f1)
  ¡Ñ (map f2)
 ............               
  ¡Ñ (map fN)   $sequence


It can easily be proven that the above is equal to:

map (f1 ¡Ñ f2 ...  ¡Ñ fN) $sequence

While your mapping operator will perform a series of mappings, each producing an
intermediate sequence and may require too much memory, the last function applies the
map function only once. The composition of all functions is applied on every element
of $sequence and the resulting sequence is produced. No additional memory for
intermediate sequences is necessary.

This shows that it is better to have a map() function and a composition operator for
expressions (in case XPath 2.0 will not fully support higher-order functions).

An operator for functional composition has an added benefit that it can be used with
***any functions***, not only with functions that operate on sequences. Thus, it can
be used to express an arbitrary sequence of processing (piping) applied on a value
of any datatype.

Just my 2 cents on this subject.

Cheers,
Dimitre Novatchev.

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

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


Current Thread