XQuery4Humanists icon indicating copy to clipboard operation
XQuery4Humanists copied to clipboard

"Alternative lookup syntax"

Open joewiz opened this issue 8 years ago • 1 comments

Hi Cliff,

In 03, around line 470, there's this paragraph:

The extra work of finding the size of the array and iterating through its members is actually not necessary when we use the alternative lookup syntax. Can you rewrite this example with the lookup syntax?

I wasn't exactly sure what you meant by "alternative lookup syntax." Did you mean the ? lookup operator? Are you asking the student to write out a more verbose path rather than use map:find()?

Joe

joewiz avatar Aug 05 '17 22:08 joewiz

Hi Joe,

Yes, I had in mind simplifying the expression like so:

let $lookup-word := local:lookup-word(?, $id, $key)
let $definitions := map:find($lookup-word($word), "definitions")
for $definition at $num in $definitions?*
return $num || ". " || $definition

In other words, I wanted to show students that the ?* operator is really a shorthand for iterating through the size of the array and calling a function to return every item in the array. Do you have a suggestion for improving the wording?

CliffordAnderson avatar Aug 05 '17 22:08 CliffordAnderson