[xquery-talk] Removing douplicate elements
Michael Kay
mhk at mhk.me.uk
Wed Aug 10 19:53:15 PDT 2005
Actually, the error message looks rather like a Saxon message. Saxon does
have tail-call optimization, and it's not obvious why it's not being used
here (which version are you using?). There isn't a built-in limit on the
depth of function calls; rather Saxon catches the StackOverflowException and
turns it into this error message.
Having said that, the algorithm looks pretty inefficient, and I'm sure one
could do better.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: talk-bounces at xquery.com
> [mailto:talk-bounces at xquery.com] On Behalf Of Martin Probst
> Sent: 10 August 2005 17:17
> To: EXTERNAL Kruse Peter (Praktikant;CR/AEA1-Si)
> Cc: talk at xquery.com
> Subject: Re: [xquery-talk] Removing douplicate elements
>
> Hi,
> your function is recursive relative to the number of elements. As your
> processor obviously does not have tail call optimization, the
> (processors) recursion level is dependent on the number of
> elements, and
> to prevent a StackOverFlowException (or sth worse with C) the
> processor
> seems to have a built in limit.
> The solution is to have a non recursive function.
>
> declare function local:notIn($pivot as node(),$list as node()*) as
> xs:boolean {
> if ( for $elem at $index in $list
> return
> if ( deep-equal($pivot, $elem) )
> then true()
> else ()
> ) then true()
> else false()
> }
>
> The trick is to return a list of boolean values, but only
> return a true
> value if the node is deep-equal, otherwise return nothing.
> The outer if
> will try to evaluate the EBV of the condition and receive an empty
> sequence (--> false) if none of the elements was deep-equal, a list
> starting with the value true otherwise.
> You just need the outer if to make sure it's exactly one boolean btw.
>
> Martin
>
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
>
More information about the talk
mailing list