[basex-talk] Trouble with wildcard lookup operator on maps?

2015-08-15 Thread Marc van Grootel
Hi,

Unless I'm not reading the spec[1] correctly then the following two
snippets should have the same result:

Example 1:


let $map := map { 'a': (1,2,3), 'b': (4,5,6)}
for $k in map:keys($map)
return array { $map($k) }

Example 2:

let $map := map { 'a': (1,2,3), 'b': (4,5,6)}
for $k in $map?*
return array { $k }

However, this is not the case. The first outputs, as I expected:

([1,2,3], [4,5,6])

The second, counter intuitively returns (on 8.2.3) this:

([1],[2],[3],[4],[5],[6])

The spec indicates that both examples result should be identical.
Didn't check if the same is going on with arrays.

Hmmm?

[1] http://www.w3.org/TR/xquery-31/#id-lookup


Re: [basex-talk] Trouble with wildcard lookup operator on maps?

2015-08-15 Thread Marc van Grootel
Hi Christian,

Ok, that clears it up. Somehow I suspected this, but I was thrown by
the statement in the spec (and my faulty intuition) that says:

If the KeySpecifier is a wildcard (*) and the context item is a map,
unary lookup is equivalent to the following expression:

  for $k in map:keys(.)
  return .($k)

I realize that if I didn't put an array {} around the return value
then this statement would be correct.

Just thought I caught a loophole there. I stand corrected. ;-)


On Sat, Aug 15, 2015 at 3:59 PM, Christian GrĂ¼n
christian.gr...@gmail.com wrote:
 Hi Marc,

 The result is correct: The FOR clause of the FLWOR expression always
 binds one item at a time. If you want to bind sequences, you should
 use arrays in your map constructor:

   let $map := map { 'a': [1,2,3], 'b': [4,5,6] }
   return $map?*

 Hope this helps,
 Christian



 On Sat, Aug 15, 2015 at 3:47 PM, Marc van Grootel
 marc.van.groo...@gmail.com wrote:
 Hi,

 Unless I'm not reading the spec[1] correctly then the following two
 snippets should have the same result:

 Example 1:


 let $map := map { 'a': (1,2,3), 'b': (4,5,6)}
 for $k in map:keys($map)
 return array { $map($k) }

 Example 2:

 let $map := map { 'a': (1,2,3), 'b': (4,5,6)}
 for $k in $map?*
 return array { $k }

 However, this is not the case. The first outputs, as I expected:

 ([1,2,3], [4,5,6])

 The second, counter intuitively returns (on 8.2.3) this:

 ([1],[2],[3],[4],[5],[6])

 The spec indicates that both examples result should be identical.
 Didn't check if the same is going on with arrays.

 Hmmm?

 [1] http://www.w3.org/TR/xquery-31/#id-lookup



-- 
--Marc