| 10:10 |
for $a in (1,2,3,4,5) where $a < 5 return 2*$a+1
|
| Zdenek Wagner |
| 10:55 |
let $in := (1,2,3,4,5)
return
map-pairs(function($a,$b){$a+$b}, $in, tail($in))
|
| Michael Kay |
| 11:00 |
declare function local:convert($list as xs:integer+) as xs:integer* {
if(count($list) < 2) then ()
else
($list[1] + $list[2], local:convert(subsequence($list, 2)))
};
local:convert((1, 2, 3, 4, 5))
|
| Viacheslav Zholudev |
| 11:32 |
declare function local:foo($in as item()*) as item()* {
for $i in subsequence($in, 1, count($in)-1)
return
$i + ($i+1)
};
local:foo( (1,2,3,4,5) )
|
| Dan McCreary |
| 11:45 |
declare function local:newseq( $seq as xs:double* ) as xs:double*
{
if( exists($seq[2]) ) (:check for more than one; don't be caught by zero:)
then ( $seq[1]+$seq[2], local:newseq( remove($seq,1) ) ) (:got a value:)
else () (:at the end of the sequence:)
};
local:newseq( ( 1,2,3,4,5 ) ) (:go!:)
|
| Ken Holman |
| 12:06 |
xquery version "1.0";
let $src := (1,2,3,4,5)
for $i in 2 to count($src)
return $src[$i] + $src[$i - 1]
and just had a glance at 1.1 and tried to cram in the count statement...
---
xquery version "1.1";
let $src := (1,2,3,4,5)
for $i in $src
count $cnt
return $src[$cnt] + $src[$cnt + 1]
---
actually, I have to admit I would prefer the 1.0 version as it appears
to be more intuitive. Mhh maybe the windowing stuff is better?
---
xquery version "1.1";
for sliding window $w in (1,2,3,4,5)
start $first at $s when fn:true()
only end $last at $e when $e - $s eq 1
return $first + $last
|
| Stefan Majewski |
| 12:21 |
xquery version "1.0";
let $integers := (1, 2, 3, 4, 5)
let $nbInt := count($integers)
for $a in $integers[position() < $nbInt],
$b in $integers[index-of($integers, $a)+1]
return $a + $b
|
| vbiragnet@1500signes.com |
| 3:08 |
Here is the (untested) 1.1 candidate:
========8<----------------
xquery version "1.1";
let $f := function ($a as xs:integer, $b as xs:integer?)
as xs:integer?
{ if ($b) then $a + $b else () }
return
let $g := function ($s as xs:integer+, $f as function(xs:integer,
xs:integer?) as xs:integer?)
as xs:integer*
{ for $i in $s return $f($s[$i], $s[$i+1]) }
return
for $s in (1 to 5)
return $g($s, $f)
========8<----------------
At least, it has been syntactically validated by
http://www.w3.org/2010/02/qt-applets/xquery11/
And here's a less elegant 1.0 solution:
========8<----------------
declare namespace my = "urn:my";
declare function my:f($a as xs:integer, $b as xs:integer?) as
xs:integer? { if ($b) then $a + $b else () };
let $in := (1 to 5)
return
for $i in ($in)
return my:f($in[$i], $in[$i+1])
========8<----------------
But this comes next to giving the result explicitly, as a static sequence.
|
| Gerrit Imsieke |
| 5:07, March 14th |
declare variable $seq := (1,2,3,4,5);
for $i in 1 to count($seq) - 1 return
$seq[$i] + $seq[$i +1]
|
| Adam Retter |
| 8:25 |
let $input := (1, 2, 3, 4, 5)
for $s in subsequence($input, 2) return $input[$s - 1] + $input[$s]
|
| Michael Müller-Hillebrand |
| 8:30 |
let $seq := (1,2,3,4,5)
return
for $i in $seq
where 2* $i != sum (for $j in 1 to $i -1 return $seq[$j])
return 2 * $i+1
|
| Hans Jurgen |
| 8:32 |
for sliding window $w in (1,2,3,4,5)
start at $s previous $p when $p
end when fn:true()
return $p + $s
|
| Benjamin Bock |
| 9:30 |
for sliding window $w in (1,2,3,4,5)
start at $s when fn:true()
only end at $e when $e - $s eq 1
return sum($w)
|
| Matthias Brantner |