[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

problem with loops

Michael Kay mhk at mhk.me.uk
Wed Jan 4 09:49:10 PST 2006


  problem with loops
> Something as shown below
> ____________________________________
> 
> 
> declare function lcl:caller()
> { 
>        let $QV1 := request:request-parameter("val1","")
>        let $count:= 0
>        let $QV1:= lcl:tracer($QV1)
> for $d in /maps/map
>        let $k:= lcl:rend($QV1)
>        let $QV2:= $QV1
>        let $QV1:= lcl:tracer($k)
>        return $QV2
> };
> ________________________________________
> 

I don't know what your various functions here are doing, but the general
approach to this kind of problem in a functional language is to use
recursion. Your loop here is a bit odd because it doesn't depend on $d, so
you seem to be using /maps/map merely to determine how many iterations there
should be. This suggests a recursive solution along these lines:

declare function f:doit (
    $QV1 as item()*
    $count as xs:integer ) as item()* {
  if ($count eq 0)
  then $QV1
  else f:doit(lcl:tracer(lcl:rend($QV1), $count - 1))
} 

I don't think that's precisely the logic, but it's difficult to reverse
engineer your algorithm from incorrect code.

Michael Kay
http://www.saxonica.com/




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.