<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>26585</bug_id>
          
          <creation_ts>2014-08-14 19:32:38 +0000</creation_ts>
          <short_desc>Proposal: fn:apply</short_desc>
          <delta_ts>2015-02-10 17:01:41 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Functions and Operators 3.1</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://www.w3.org/Bugs/Public/show_bug.cgi?id=26889</see_also>
    
    <see_also>https://www.w3.org/Bugs/Public/show_bug.cgi?id=26558</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Marc">marc.van.grootel</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          <cc>christian.gruen</cc>
    
    <cc>cmsmcq</cc>
    
    <cc>leo</cc>
    
    <cc>liam</cc>
    
    <cc>mike</cc>
    
    <cc>r.stapper</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>110190</commentid>
    <comment_count>0</comment_count>
    <who name="Marc">marc.van.grootel</who>
    <bug_when>2014-08-14 19:32:38 +0000</bug_when>
    <thetext>XQuery 3.0 introduced functions that are derived from functional programming.
Function items can be passed as arguments to functions like fn:fold-left().
Together they allow a more functional style of coding. Most of these functions
can be used to perform map, filter, reduce on sequences.

However, one important function that is missing and for which I do not know a
reasonable workaround for is &quot;apply&quot; [1]. The wikipedia page shows that many
languages have ways to achieve this and Clojure has a function with the same
name [2].

In XQuery we can bind a variable to a function item. But when we want to use
it we are limited to one argument.

  $f = function my-add($a,$b,$c) { $a + $b + $c }
  $args = (1,2,3)
  
  $f($args) == $f((1,2,3))

If we had an apply function this would do it.
  
  fn:apply($f, $args) == $f(1,2,3)

Of course we could rewrite the function my-add to something like:

  $f = function my-add($seq) { sum($seq) }
  
  $f($args) == 6
  
But this is only practical for a limited number of cases and the function body
would need to unpack the sequence, and we also lose the type checking.

This limitation also shows with the proposed arrow operator (=&gt;).

Someone coming from a language like Clojure, Lisp or Scheme would interpret the
following

  (1,2,3) =&gt; $f

to mean 

  $f(1,2,3)

but in XQuery it would mean

  $f((1,2,3))

The arrow operator is similar to Clojure&apos;s threading operator (-&gt;) [3].

Clojure:

  (-&gt; (1 2 3) f1 f2) == (f2 (f1 1 2 3))

Note that in Clojure -&gt; is a macro which re-writes the form before the
compiler will see it. But I digress.

XQuery:
  
  (1,2,3) =&gt; $f1 =&gt; $f2 
  
  $f2($f1((1,2,3))

Maybe this is a consequence of the fact that sequences cannot be nested, and
are effectively flattened.

I cannot oversee all the consequences but like a map may contain other maps
arrays can be nested so they could be used for &quot;apply&quot; semantics.

Currently we have:

  (1,2,3) =&gt; $f

  $f((1,2,3))

With array apply semantics:
  
  [1,2,3] =&gt; $f1 =&gt; $f2
  
  == $f2($f1(1,2,3))
  
  [(1,2),(3,4)] =&gt; $f1
  
  == $f1((1,2),(3,4))
  
  == fn:apply($f1, [(1,2),(3,4)])

On the surface this looks like an elegant solution to me and is closer to
the apply semantics in other languages.

A particular use case for fn:apply arose when I tried implementing Clojure Ring
and Compojure libraries in XQuery. These are comparable to WSGI in Python and
Rack in Ruby.

Below I simplified things but I hope it illustrates a concrete use case.

I have a function for defining a routing handler which maps an HTTP GET request to
a handler function. The def-route() signature is

  function(
    $method as xs:string,
    $url-template as xs:string,
    $params as array(*),
    $handler as function(*)
  ) as function(map(*)) as map(*)
  
This means that a route handler function is something that takes a request
map as input and produces a response map as output.

  $handler = 
      function($name, $age) { 
        &apos;Person: &apos; || $name || &apos; (age &apos; || $age &apos;)&apos; 
      }
      
  $route = def-route(&apos;GET&apos;, &apos;/person/{name}/{age}&apos;, [&apos;name&apos;, &apos;age&apos;], $handler)
 
  $route(request(&apos;GET&apos;, &apos;/person/Joe/10&apos;))

When a GET request comes in on &apos;/person/Joe/10&apos;. The route-handler $route
matches and the &apos;name&apos; and &apos;age&apos; parameters are parsed from the URL and added to
the request map. The third argument is an array that specifies which keys need
to be taken from the request map and builds the $params array: [&apos;Joe&apos;, &apos;10&apos;].
Finally it can invoke the $handler using

  fn:apply($handler, $params)

or

  $params =&gt; $handler

  == [&apos;Joe&apos;, &apos;10&apos;] =&gt; $handler
  
This results in a response(&apos;Person: Joe (age 10)&apos;) which is then rendered to the
browser.

Note that the handler does not need to know where to find the parameters because
this is set up by the $route handler thus achieving a clean separation of
concerns and the possibility of using $handler in other situations because
it is not tied to the plumbing/routing logic.

As I said earlier, I may not be able to oversee all the consequences as I&apos;m not
super intimate with all the specs involved. Or, my pseudo code is confusing. Mea
culpa.

--Marc

[1] http://en.wikipedia.org/wiki/Apply
[2] http://clojuredocs.org/clojure_core/clojure.core/apply
[3] http://clojuredocs.org/clojure_core/clojure.core/-%3E</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>110192</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-08-14 20:03:02 +0000</bug_when>
    <thetext>In the past it hasn&apos;t been possible to treat the list of arguments of a function as a single value because sequences can&apos;t be nested, as you suggest. That difficulty is partly solved by the introduction of arrays. But I think there are considerable difficulties that remain, notably the fact that the arity of a function in XQuery is so much part of its nature. Doing this would be powerful, but a lot of work to do well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>110352</commentid>
    <comment_count>2</comment_count>
      <attachid>1503</attachid>
    <who name="Rob">r.stapper</who>
    <bug_when>2014-08-20 13:44:37 +0000</bug_when>
    <thetext>Created attachment 1503
demo for apply (limited) functionality built in xquery</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>110353</commentid>
    <comment_count>3</comment_count>
      <attachid>1504</attachid>
    <who name="Rob">r.stapper</who>
    <bug_when>2014-08-20 13:52:31 +0000</bug_when>
    <thetext>Created attachment 1504
apply module built in xquery (limited functionality)

The &apos;APPLY:argument.constructor&apos; function gives problems in xquery. But since the module should be built in java these problems probably can be overcome.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>110354</commentid>
    <comment_count>4</comment_count>
    <who name="Rob">r.stapper</who>
    <bug_when>2014-08-20 14:03:06 +0000</bug_when>
    <thetext>for inspiration a apply-function built in xquery. The challenge in xquery is the (re-)creation of the argumentlist for the evaluationstring. But if the apply-function would be a part of the xquery-language itself it probably will be built in java. I&apos;m not a java-expert but I wander if the problem that exists on xquery-level also exists on java-level.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>110577</commentid>
    <comment_count>5</comment_count>
      <attachid>1505</attachid>
    <who name="Marc">marc.van.grootel</who>
    <bug_when>2014-08-26 07:31:14 +0000</bug_when>
    <thetext>Created attachment 1505
apply with array semantics

Rob&apos;s example almost worked for me. I have added some extra argument serialization and handling of arrays as described in my proposal. Here&apos;s the adapted code. Note that 1) it may now be BaseX specific due to use of map and array modules and 2) I heavily reformatted the code so it matches the other code in my little library and 3) I have done little testing on this so there are probably many potholes.
Next attachment will have some unit tests.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>110578</commentid>
    <comment_count>6</comment_count>
      <attachid>1506</attachid>
    <who name="Marc">marc.van.grootel</who>
    <bug_when>2014-08-26 07:32:17 +0000</bug_when>
    <thetext>Created attachment 1506
unit tests for apply with array semantics

Here are the BaseX specific unit tests.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111389</commentid>
    <comment_count>7</comment_count>
    <who name="Leo Wörteler">leo</who>
    <bug_when>2014-09-11 15:22:04 +0000</bug_when>
    <thetext>The current implementation of the arrow operator in the Working Draft [1] defines it as a syntactic macro:

&gt; If `$i` is an item and `f()` is a function, then `$i=&gt;f()` is equivalent
&gt; to `f($i)`, and `$i=&gt;f($j)` is equivalent to `f($i, $j)`.

I think this is not very elegant and possibly confusing. Since e.g. `local:foo#0` and `local:foo#1` can be completely different functions in XQuery, it is potentially dangerous that in

  1 =&gt; local:bar() =&gt; local:foo()

it is not immediately obvious which of them is called.

I would propose that the second argument of `=&gt;` should instead be a function item taking one argument. Then `$arg =&gt; $f` can be translated into `$f($arg)` directly and the Spec can define it simply as equivalent to:

  function op:arrow-apply(
    $arg as item()*,
    $func as function(item()*) as item()*
  ) as item()* {
    $func($arg)
  };

As a nice bonus this also makes the feature more flexible because the argument to be inserted does not have to be the first one in the function:

  $file-extension =&gt; csv:get-separator() =&gt; (tokenize($line, ?))()

could be written as

  $file-extension =&gt; csv:get-separator#1 =&gt; tokenize($line, ?)

Everything that was possible before should still work when adding a &quot;?&quot; at the start of the ArgumentList of each right-hand side of `=&gt;`. The example from the Spec becomes

  $string =&gt; upper-case(?) =&gt; normalize-unicode(?) =&gt; tokenize(?, &quot;\s+&quot;)

or (shorter and more elegant):

  $string =&gt; upper-case#1 =&gt; normalize-unicode#1 =&gt; tokenize(?, &quot;\s+&quot;)

In conclusion, using function items is more flexible and less confusing, and the syntactic translation scheme makes for only marginally less verbose tyntax.

[1] http://www.w3.org/TR/2014/WD-xquery-31-20140424/#id-arrow-operator</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>112012</commentid>
    <comment_count>8</comment_count>
    <who name="Christian Gruen">christian.gruen</who>
    <bug_when>2014-09-23 11:29:24 +0000</bug_when>
    <thetext>I copied Leo Wörteler&apos;s proposal in an extra issue: https://www.w3.org/Bugs/Public/show_bug.cgi?id=26889</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114189</commentid>
    <comment_count>9</comment_count>
    <who name="Liam R E Quin">liam</who>
    <bug_when>2014-10-28 22:02:29 +0000</bug_when>
    <thetext>The WG is considering comment 7 separately (thank you, Christian, for copying it).

On the main subsance of this issue, it&apos;s possible (I think) that a function like fn:apply($f as function, $args as array) could be defined by F &amp; O in the future, but the Working Groups have not made such a decision now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115683</commentid>
    <comment_count>10</comment_count>
    <who name="C. M. Sperberg-McQueen">cmsmcq</who>
    <bug_when>2014-11-29 02:27:53 +0000</bug_when>
    <thetext>On the joint call of 25 November I took an action to try to work out a simple use case for the fn:apply() function requested by the OP, as sketched by Michael Kay in [1] and as commented on by John Snelson in [2].

[1] https://lists.w3.org/Archives/Member/w3c-xsl-query/2014Nov/0019.html
[2] https://lists.w3.org/Archives/Member/w3c-xsl-query/2014Nov/0026.html

I have posted the results separately to the public QT comments list [3], to avoid overburdening a Bugzilla comment.

[3] http://lists.w3.org/Archives/Public/public-qt-comments/2014Nov/0115.html

In that mail, I provide examples of the use of fn:apply() as sketched in [1] for currying functions, for composing functions, and for use in meta-circular interpreters.

The bottom line is that while I agree with Michael Kay and John Snelson that variable-arity functions would be handy, and would make fn:apply() more useful and convenient, I believe that it&apos;s useful enough to be included in the spec even without variable-arity functions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115812</commentid>
    <comment_count>11</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-12-02 22:40:41 +0000</bug_when>
    <thetext>The proposal to add an fn:apply() function was accepted.

The semantics of fn:apply($f, [$a, $b, $c, ...]) are the same as $f($a, $b, $c, ...) but of course the arity does not need to be known statically.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1503</attachid>
            <date>2014-08-20 13:44:37 +0000</date>
            <delta_ts>2014-08-20 13:44:37 +0000</delta_ts>
            <desc>demo for apply (limited) functionality built in xquery</desc>
            <filename>applyDemo.xq</filename>
            <type>text/plain</type>
            <size>455</size>
            <attacher name="Rob">r.stapper</attacher>
            
              <data encoding="base64">aW1wb3J0IG1vZHVsZSBuYW1lc3BhY2UgQVBQTFkgPSAiQVBQTFkiIDsgKDogZHdvcmtzIG9ubHkg
Zm9yIGEgc3Vic2V0IG9mIGRhdGEgdHlwZXM6KQoKbGV0ICRmb28yIDo9CmZ1bmN0aW9uKCAkYSwg
JGIpCiAgICAgICAgeyAkYSB8fCBzdHJpbmcoICRiKQogICAgICAgIH0KCmxldCAkZm9vMyA6PQpm
dW5jdGlvbiggJGEsICRiLCAkYykKICAgICAgICB7ICRhICsgJGIgKyAkYwogICAgICAgIH0KCmxl
dCAkZm9vNCA6PQpmdW5jdGlvbiggJGEsICRiLCAkYywgJGQpCiAgICAgICAgeyAkYSB8fCAkYiB8
fCAkYyB8fCAkZAogICAgICAgIH0KCnJldHVybiAoIEFQUExZOmFwcGx5KCAkZm9vMiwgKCAnbnVt
YmVyXycsIDIpKQogICAgICAgLCBBUFBMWTphcHBseSggJGZvbzMsICggMSwgMiwgMykpCiAgICAg
ICAsIEFQUExZOmFwcGx5KCAkZm9vNCwgKCAiYSIsICJiIiwgImMiLCAiZCIpKQogICAgICAgKQo=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1504</attachid>
            <date>2014-08-20 13:52:31 +0000</date>
            <delta_ts>2014-08-20 13:52:31 +0000</delta_ts>
            <desc>apply module built in xquery (limited functionality)</desc>
            <filename>APPLY.xqm</filename>
            <type>text/plain</type>
            <size>1928</size>
            <attacher name="Rob">r.stapper</attacher>
            
              <data encoding="base64">bW9kdWxlIG5hbWVzcGFjZSBBUFBMWSA9ICJBUFBMWSIgOwoKKDogYnVpbHQgaW4gamF2ZSBhbmQg
ZXh0ZW5kIHhxdWVyeSBsYW5ndWFnZTopCmRlY2xhcmUgJXByaXZhdGUgZnVuY3Rpb24gQVBQTFk6
c2VxdWVuY2UuY29uc3RydWN0b3IKICAgICAgKCAkaXRlbXMpCiAgICAgIHsgY29uY2F0KCAiKCAi
CiAgICAgICAgICAgICAgLCBzdHJpbmctam9pbiggJGl0ZW1zLCAnLCAnKQogICAgICAgICAgICAg
ICwgIikiCiAgICAgICAgICAgICAgKSAKICAgICAgfSA7CgpkZWNsYXJlICVwcml2YXRlIGZ1bmN0
aW9uIEFQUExZOnBhcmFtZXRlckxpc3QuY29uc3RydWN0b3IKICAgICAgKCAkYXJncy5hbW91bnQK
ICAgICAgKQogICAgICB7IEFQUExZOnNlcXVlbmNlLmNvbnN0cnVjdG9yKCAoIDEgdG8gJGFyZ3Mu
YW1vdW50KSAhIGNvbmNhdCggIiRhcmciLCAuKSkKICAgICAgfSA7CgpkZWNsYXJlICVwcml2YXRl
IHZhcmlhYmxlICRBUFBMWTphcmd1bWVudExpc3RDb25zdHJ1Y3Rvci5uYW1lIDo9ICJsb2NhbDph
cmd1bWVudExpc3QuY29uc3RydWN0b3IiIDsKCmRlY2xhcmUgJXByaXZhdGUgZnVuY3Rpb24gQVBQ
TFk6YXJndW1lbnRMaXN0Q29uc3RydWN0b3IuY29uc3RydWN0b3IKICAgICAgKCAkcGFyYW1hdGVy
TGlzdCkKICAgICAgeyBjb25jYXQoICJkZWNsYXJlICVwcml2YXRlIGZ1bmN0aW9uICIKICAgICAg
ICAgICAgICAsICRBUFBMWTphcmd1bWVudExpc3RDb25zdHJ1Y3Rvci5uYW1lCiAgICAgICAgICAg
ICAgLCAkcGFyYW1hdGVyTGlzdAogICAgICAgICAgICAgICwgInsgZnVuY3Rpb24oICRmKSB7ICRm
IgogICAgICAgICAgICAgICwgJHBhcmFtYXRlckxpc3QKICAgICAgICAgICAgICAsICJ9IH0gOyIK
ICAgICAgICAgICAgICApCiAgICAgIH0gOwooOiBwcm9ibGVtIGluIHhxdWVyeSBidXQgc2hvdWxk
IGJlIGRvLWFibGUgaW4gamF2YTopCmRlY2xhcmUgJXByaXZhdGUgZnVuY3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1Y3RvciggJGFyZ3MpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAs
ICIoIC4pIgogICAgICAgICAgICAgICAgICAgICAgICAgICApCiAgICAgICAgICAgICAgICAgICAs
IG1hcHsgJycgOiAkZm59CiAgICAgICAgICAgICAgICAgICApCiAgICAgIH0gOwo=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1505</attachid>
            <date>2014-08-26 07:31:14 +0000</date>
            <delta_ts>2014-08-26 07:31:14 +0000</delta_ts>
            <desc>apply with array semantics</desc>
            <filename>apply.xqm</filename>
            <type>text/plain</type>
            <size>2391</size>
            <attacher name="Marc">marc.van.grootel</attacher>
            
              <data encoding="base64">bW9kdWxlIG5hbWVzcGFjZSBhcHBseSA9ICdodHRwOi8veG9rb21vbGEuY29tL3hxdWVyeS9mb2xk
L3V0aWxzL2FwcGx5JzsKCig6fgogOiBBcHBseSBmdW5jdGlvbiAodXNpbmcgeHF1ZXJ5OmV2YWwp
IGNvbnRyaWJ1dGVkIGJ5CiA6IFJvYiBTdGFwcGVyIGluIGFuc3dlciB0byBteSBwcm9wb3NhbCBm
b3IgYWRkaW5nCiA6IGZuOmFwcGx5IHRvIFhRdWVyeSAzLjEuCiA6CiA6IEBzZWUgaHR0cHM6Ly93
d3cudzMub3JnL0J1Z3MvUHVibGljL3Nob3dfYnVnLmNnaT9pZD0yNjU4NQogOikKCmRlY2xhcmUg
JXByaXZhdGUgZnVuY3Rpb24gYXBwbHk6c2VxdWVuY2UoJGl0ZW1zKSB7CiAgICBjb25jYXQoJygn
LCBzdHJpbmctam9pbigkaXRlbXMsICcsICcpLCAnKScpIAp9OwoKZGVjbGFyZSAlcHJpdmF0ZSBm
dW5jdGlvbiBhcHBseTpwYXJhbWV0ZXItbGlzdCgkYXJnY291bnQpIHsKICAgIGFwcGx5OnNlcXVl
bmNlKAogICAgICAgICgxIHRvICRhcmdjb3VudCkgISBjb25jYXQoIiRhcmciLCAuKQogICAg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uIGFwcGx5OmFyZ3VtZW50LWxpc3QoJGFyZ3MpIHsK
ICAgIGFwcGx5OnNlcXVlbmNlKAogICAgICAgIHR5cGVzd2l0Y2ggKCRhcmdzKQogICAgICAgICAg
ICBjYXNlIGFycmF5KCopCiAgICAgICAgICAgICAgICByZXR1cm4gCiAgICAgICAgICAgICAgICAg
ICAgZm9yICRpIGluIDEgdG8gYXJyYXk6c2l6ZSgkYXJncykgCiAgICAgICAgICAgICAgICAgICAg
ICAgIHJldHVybiBhcHBseTphcmd1bWVudCgkYXJncygkaSkpCiAgICAgICAgICAgIGRlZmF1bHQK
ICAgICAgICAgICAgICAgIHJldHVybiAkYXJncyAhIGFwcGx5OmFyZ3VtZW50KC4pCiAgICApCn07
CgpkZWNsYXJlICVwcml2YXRlIGZ1bmN0aW9uIGFwcGx5OmFyZ3VtZW50LWxpc3QtY29uc3RydWN0
b3ItY2FsbGVyKCRhcmd1bWVudC1saXN0KSB7CiAgICBjb25jYXQoCiAgICAgICAgJGFwcGx5OmFy
Z3VtZW50LWxpc3QtY29uc3RydWN0b3ItbmFtZSwKICAgICAgICAkYXJndW1lbnQtbGlzdAogICAg
KQp9OwoKZGVjbGFyZSBmdW5jdGlvbiBhcHBseTphcHBseSgkZm4sICRhcmdzKSB7CiAgICB4cXVl
cnk6ZXZhbCgKICAgICAgICBjb25jYXQoCiAgICAgICAgICAgIGFwcGx5OmFyZ3VtZW50LWxpc3Qt
Y29uc3RydWN0b3IoCiAgICAgICAgICAgICAgICBhcHBseTpwYXJhbWV0ZXItbGlzdCgKICAgICAg
ICAgICAgICAgICAgICB0eXBlc3dpdGNoICgkYXJncykKICAgICAgICAgICAgICAgICAgICAgICAg
Y2FzZSBhcnJheSgqKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGFycmF5OnNp
emUoJGFyZ3MpCiAgICAgICAgICAgICAgICAgICAgICAgIGRlZmF1bHQKICAgICAgICAgICAgICAg
ICAgICAgICAgICAgIHJldHVybiBjb3VudCgkYXJncykKICAgICAgICAgICAgICAgICkKICAgICAg
ICAgICAgKSwKICAgICAgICAgICAgYXBwbHk6YXJndW1lbnQtbGlzdC1jb25zdHJ1Y3Rvci1jYWxs
ZXIoCiAgICAgICAgICAgICAgICBhcHBseTphcmd1bWVudC1saXN0KCRhcmdzKSksCiAgICAgICAg
ICAgICcoLiknCiAgICAgICAgKSwKICAgICAgICBtYXAgeyAnJzogJGZuIH0KICAgICkKfTsK
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1506</attachid>
            <date>2014-08-26 07:32:17 +0000</date>
            <delta_ts>2014-08-26 07:32:17 +0000</delta_ts>
            <desc>unit tests for apply with array semantics</desc>
            <filename>test-apply.xqm</filename>
            <type>text/plain</type>
            <size>1604</size>
            <attacher name="Marc">marc.van.grootel</attacher>
            
              <data encoding="base64">eHF1ZXJ5IHZlcnNpb24gIjMuMCI7CgooOn4KIDogVGVzdHMgZm9yIGFwcGx5IGZ1bmN0aW9uICh1
c2luZyB4cXVlcnk6ZXZhbCkgY29udHJpYnV0ZWQgYnkKIDogUm9iIFN0YXBwZXIgaW4gYW5zd2Vy
IHRvIG15IHByb3Bvc2FsIGZvciBhZGRpbmcKIDogYXBwbHkgdG8gWFF1ZXJ5IDMuMS4KIDoKIDog
QHNlZSBodHRwczovL3d3dy53My5vcmcvQnVncy9QdWJsaWMvc2hvd19idWcuY2dpP2lkPTI2NTg1
CiA6KQptb2R1bGUgbmFtZXNwYWNlIHRlc3QgPSAnaHR0cDovL3hva29tb2xhLmNvbS94cXVlcnkv
Zm9sZC90ZXN0cyc7CgpkZWNsYXJlIGRlZmF1bHQgZnVuY3Rpb24gbmFtZXNwYWNlICdodHRwOi8v
eG9rb21vbGEuY29tL3hxdWVyeS9mb2xkL3V0aWxzL2FwcGx5JzsKCmltcG9ydCBtb2R1bGUgbmFt
ZXNwYWNlIGFwcGx5ID0gJ2h0dHA6Ly94b2tvbW9sYS5jb20veHF1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B0ZXN0OmFwcGx5LWFycmF5KCkgewogICAgdW5pdDphc3NlcnQtZXF1YWxz
KAogICAgICAgIGFwcGx5KHRlc3Q6c3VtIzIsIFsyLDRdKSwKICAgICAgICA2CiAgICApCn07Cgpk
ZWNsYXJlICV1bml0OnRlc3QgZnVuY3Rpb24gdGVzdDphcHBseS1hcnJheS13aXRoLXNlcSgpIHsK
ICAgIHVuaXQ6YXNzZXJ0LWVxdWFscygKICAgICAgICBhcHBseSgKICAgICAgICAgICAgZnVuY3Rp
b24oJGEsJGIpIHsKICAgICAgICAgICAgICAgICgkYVsxXSAqICRhWzJdKSArICgkYlsxXSAqICRi
WzJdKQogICAgICAgICAgICB9LCBbKDEsMiksKDMsNCldCiAgICAgICAgKSwKICAgICAgICAxNAog
ICAgKQp9Owo=
</data>

          </attachment>
      

    </bug>

</bugzilla>