Figure out what "Implicit and explicit return, e.g. `0` vs `return $result`" means
gabikeane opened this issue · comments
I don't know what the context of this question is (I suspect XQuery), but in general a '0' return code is a magic number, meaning a number that has a meaning behind it that is known to the original developers and other programmers/users of the software. '0' usually means finished with no errors. 'return $result' means give back the value of whatever the variable result points to.
@rhdekker The issue came up because in some brief notes from an XQuery (good guess!) session we found the line in question. My guess is that it might be a reference to implicit vs explicit for
structures. In XQuery, we can count the speakers in each act of play in a FLWOR:
for $act in $acts
return count($act/descendant::speaker)
or with a single line of XPath
$acts/count(descendant::speaker)
The FLWOR has an explicit for
and an explicit return
, but the XPath returns the same results because path expressions always return sequences.
I’ve written to Leif-Jöran (who prepared the original teaching notes) for clarification, but he hasn’t responded yet. If the preceding sounds credible, I'll write it into the tutorial as a clarification.
@djbpitt Can you point me to the file in the Github repository were I can see the original notes? I would have guessed that Leif-Jöran would have written implicit versus explicit for instead of return value in that case. I also don't see how '0' or 'return $result' makes sense in for loop versus path query. The different loops are interesting nonetheless. It would not hurt to add it to the material either way.
@rhdekker The cryptic original is at line 22 of a538d22#diff-af4662120513661efb398e1af4eccfbaL22