This is actually very straightforward. "return" is a keyword, used in FLWOR expressions and a few other places. There is no standalone "return" in XQuery. Thus:

   let $x:=0 return (23)

is a valid (if uninteresting) FLWOR expression that is equivalent to the even less interesting (but still valid) expression:

   (23)

And a standalone "return" is illegal:

   return (23) (: error :)

Where you have included parentheses below, you are calling a function named "return" and XQuery works as expected. It's a bad idea to name a function using a keyword as a name, but XQuery allows it. If you replace "return(...)" with "foo(...)" in the expressions below, the intended meaning will be clear.

The last two XQuery expressions should return errors (and do in the online Zorba XQuery processor I tried them in). As noted above, this is because there is no standalone use of the "return" keyword -- either the processor you are using has a bug or you haven't shown us the entire expression.

Thanks,

-- Ron

On 10/1/2012 5:34 PM, Michael Sokolov wrote:
On 10/1/2012 10:48 AM, Michael Kay wrote:
There is no function called "return". Just remove the keyword.
Depending on the context, you might need to remove the outer curly
braces as well.

It's a little confusing because you can say

let $x:=0 return 23

but you can't say

return 23

Actually if you really start to dig, it becomes a lot confusing

you can say

let $x := 0 return (23)

but in that instance return is not a function call; the parentheses here
are constructing a sequence (of one item)

But if you say

declare default function namespace "x";
declare function return ($x) { $x+1 };
return (23)

that does seem to return 24 for at least one processor that I tried,
which seems truly bizarre (to me, anyway)

yet

declare default function namespace "x";
declare function return ($x) { $x+1 };
return 23

returns 23

while

declare default function namespace "x";
declare function return ($x) { $x+1 };
return return(23)

returns 24

-Mike Sokolov


_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to