[xquery-talk] How much laziness is permitted?

John Snelson john.snelson at oracle.com
Wed Mar 11 17:24:42 PST 2009


Michael Kay wrote:
>> 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.

Yes, that's true.

John

-- 
John Snelson, Oracle Corporation            http://snelson.org.uk/john
Berkeley DB XML:            http://oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net


More information about the talk mailing list