[xquery-talk] How much laziness is permitted?

Michael Kay mike at saxonica.com
Wed Mar 11 17:08:25 PST 2009


> 
> Pavel Minaev wrote:
> >   (* module 1 *)
> >   declare function m1:gen() {
> >       for $x in 1 to 10000 return if ($x lt 10000) then $x else error()
> >   }
> > 
> >   (* module 2 *)
> >   declare function m2:trygen() {
> >     try { m1:gen() } catch * { () }
> >   };
> > 
> 
> John Snelson: As it turns out, try/catch is actually a blocking operation 
> on lazy evaluation. 

I think that's certainly true of a naive implementation (and it's largely
true of Saxon's current implementation). However, I think some optimization
rewrites are still legitimate: for example, given an expression such as

(try{ E } catch * {F})[1]

I think an implementation can legitimately rewrite this as

try{ E[1] } catch * {F[1]}

exploiting the knowledge that E[1] cannot throw an error unless E throws an
error.

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



More information about the talk mailing list