[Bug 26585] Proposal: fn:apply

https://www.w3.org/Bugs/Public/show_bug.cgi?id=26585

Leo Wörteler <leo@woerteler.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |leo@woerteler.de

--- Comment #7 from Leo Wörteler <leo@woerteler.de> ---
The current implementation of the arrow operator in the Working Draft [1]
defines it as a syntactic macro:

> If `$i` is an item and `f()` is a function, then `$i=>f()` is equivalent
> to `f($i)`, and `$i=>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 => local:bar() => local:foo()

it is not immediately obvious which of them is called.

I would propose that the second argument of `=>` should instead be a function
item taking one argument. Then `$arg => $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 => csv:get-separator() => (tokenize($line, ?))()

could be written as

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

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

  $string => upper-case(?) => normalize-unicode(?) => tokenize(?, "\s+")

or (shorter and more elegant):

  $string => upper-case#1 => normalize-unicode#1 => tokenize(?, "\s+")

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

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Thursday, 11 September 2014 15:22:09 UTC