- From: <bugzilla@jessica.w3.org>
- Date: Sun, 27 Jul 2014 20:17:56 +0000
- To: public-qt-comments@w3.org
https://www.w3.org/Bugs/Public/show_bug.cgi?id=25445
--- Comment #4 from Jonathan Robie <jonathan.robie@gmail.com> ---
Here is a set of examples from the use cases in three different syntaxes:
** XQuery 3.1 CWD
The syntax in the current working draft.
** Changing array { } to array(())
Michael's proposal in comment 0 of this BZ. To my eyes, these
expressions are harder to read because of the number of parentheses.
** Changing array { } to [], changing [] to array()
A counterproposal that allows us to replace one of our array
constructor syntaxes with array() rather than array(())
Here are some examples from the use cases.
Note:
I did not find an example that depends on the comma behavior
we have defined for the current [] operator, so I will try to
construct such an example in a subsequent comment.
* Example 1:
** XQuery 3.1 CWD
declare function local:spellcheck($languages, $text)
{
map:new (
{ "languages" : $languages },
{ "raw" : $text },
for $l in $languages
return map {
$l : array { $text ! ext:sc($l, .) }
}
)
};
** Changing array { } to array(())
declare function local:spellcheck($languages, $text)
{
map:new (
{ "languages" : $languages },
{ "raw" : $text },
for $l in $languages
return map {
$l : array (( $text ! ext:sc($l, .) ))
}
)
};
** Changing array { } to [], changing [] to array()
declare function local:spellcheck($languages, $text)
{
map:new (
{ "languages" : $languages },
{ "raw" : $text },
for $l in $languages
return map {
$l : array [ $text ! ext:sc($l, .) ]
}
)
};
* Example 2:
** XQuery 3.1 CWD
[
for $w in $s()
return array { "pos" : $w(2), "lemma" : $w(1) }
]
** Changing array { } to array(())
[
for $w in $s()
return array (( "pos" : $w(2), "lemma" : $w(1) ))
]
** Changing array { } to [], changing [] to array()
[
for $w in $s()
return [ "pos" : $w(2), "lemma" : $w(1) ]
]
* Example 3:
** XQuery 3.1 CWD
map {
true() : array { $s[$p(.)] },
false() : array { $s[not($p(.))] }
}
** Changing array { } to array(())
map {
true() : array (( $s[$p(.)] )),
false() : array (( $s[not($p(.))] ))
}
** Changing array { } to [], changing [] to array()
map {
true() : [ $s[$p(.)] ],
false() : [ $s[not($p(.))] ]
}
* Example 4:
** XQuery 3.1 CWD
declare function local:mult( $matrix1, $matix2 )
{
if (length($matrix1) != length($matrix2(1))
then error("Matrices must be m*n and n*p to multiply!")
else array {
for $i in 1 to length($matrix1)
return array {
for $j in 1 to length($matrix2(1))
return
sum (
for $k in 1 to length($matrix2)
return $matrix1($i)($k) * $matrix2($k)($j)
)
}
}
};
** Changing array { } to array(())
declare function local:mult( $matrix1, $matix2 )
{
if (length($matrix1) != length($matrix2(1))
then error("Matrices must be m*n and n*p to multiply!")
else array ((
for $i in 1 to length($matrix1)
return array ((
for $j in 1 to length($matrix2(1))
return
sum (
for $k in 1 to length($matrix2)
return $matrix1($i)($k) * $matrix2($k)($j)
)
))
))
};
** Changing array { } to [], changing [] to array()
declare function local:mult( $matrix1, $matix2 )
{
if (length($matrix1) != length($matrix2(1))
then error("Matrices must be m*n and n*p to multiply!")
else [
for $i in 1 to length($matrix1)
return [
for $j in 1 to length($matrix2(1))
return
sum (
for $k in 1 to length($matrix2)
return $matrix1($i)($k) * $matrix2($k)($j)
)
]
]
};
* Example 5: assign items to groups
Note: We don't have really good use cases in our document for this.
I don't consider this one strong, but it illustrates the syntax.
** XQuery 3.1 WD
let $x := (1, 2, 3, 4, 5, 6, 7, 8, 9)
return [$x[. mod 2 eq 0], $x[. mod 3 eq 0], $x[. mod 5 eq 0]]
** Changing array { } to array(())
(Same as above.)
let $x := (1, 2, 3, 4, 5, 6, 7, 8, 9)
return [$x[. mod 2 eq 0], $x[. mod 3 eq 0], $x[. mod 5 eq 0]]
** Changing array { } to [], changing [] to array()
let $x := (1, 2, 3, 4, 5, 6, 7, 8, 9)
return array( $x[. mod 2 eq 0], $x[. mod 3 eq 0], $x[. mod 5 eq 0])
--
You are receiving this mail because:
You are the QA Contact for the bug.
Received on Sunday, 27 July 2014 20:17:57 UTC