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

Re: Just the first 'x' elements within a for-each

Subject: Re: Just the first 'x' elements within a for-each
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Mon, 17 Mar 2003 19:56:25 +0100
haskell foldr
Hi Jeni,

"Jeni Tennison" <jeni@xxxxxxxxxxxxxxxx> wrote in message
news:192796966587.20030317174203@xxxxxxxxxxxxxxxxxxx
> Hi Simon,
>
> > I've tried numerous connotations of for-each loops, recursive
> > functions etc but for the life of me I can't seem to get something
> > which will only print/process the first 'x' (in my case x is 2)
> > elements and then bail out of the for-each or just simply ignore the
> > remaining ones found.
>
> In declarative programming, you can't "bail out".

Not true. This is possible if a recursively called template was used.

position() &lt;= $n

would be the "stop criterion" of the recursion.


It is also possible within an implementation of lazy evaluation.

E.g. in Haskell Prelude the function foldr is defined as follows:

foldr :: (a -> b -> b) -> b -> [a] -> b

foldr f z [] = z

foldr f z (x:xs) = f x (foldr f z xs)


Let f is defined like this:

f 0 y = 0
f x y = x * y

Then

foldr f  1 [1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 10]

(this is the definition of the product of all numbers in a list)

will return the result

0

without ever going past the 4-th element of the list.

In this way we could operate even on lists of infinite length.



I have implemented a kind of lazy evaluation using FXSL and am currently
playing with it.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




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


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.