<?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>29869</bug_id>
          
          <creation_ts>2016-09-26 06:31:13 +0000</creation_ts>
          <short_desc>Concise syntax for inline functions</short_desc>
          <delta_ts>2016-12-07 18:35:10 +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>Requirements for Future Versions</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <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="Michael Kay">mike</reporter>
          <assigned_to name="Jim Melton">jim.melton</assigned_to>
          <cc>benito</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>127529</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-09-26 06:31:13 +0000</bug_when>
    <thetext>Inline functions in XQuery are verbose. Consider

fn:sort($employees, function($emp as element(employee)) { $emp/@salary })

Programming in a purely function style becomes a lot easier with a compact syntax for writing inline functions. Compare:

XQuery (1)
function($x as xs:integer, $y as xs:integer) { $x + $y }

XQuery (2)
function($x, $y) {$x + $y}

Javascript 6
(x, y) =&gt; x+y

Java 8
(int x, int y) -&gt; x+y

Scala (1)
(x: Int, y: Int) =&gt; x + y

Scala (2)
_ + _

Haskell
\ x y -&gt; x + y

Python
lambda x, y: x + y


A couple of suggestions:

(a) Many use cases for simple inline functions take a single item as argument, and we could exploit the existing use of &quot;.&quot; for the context item for such cases. For example use

\{. + 1} as shorthand for
function($x as item()){$x/(. + 1)}

allowing constructs such as

fn:sort($employees, \{@salary})

(b) For functions without declared types, we could implicitly declare the arguments as $1, $2, etc:

\{$1 + $2}

allowing

fn:sort($employees, \{$1/@salary})

Or we could combine the two ideas with &quot;.&quot; being a synonym for ($1 treat as item()), thus

fn:sort($employees, \{@salary})

I&apos;m not wedded to the backslash. Alternatives to \{$1+2} would be fn{$1+$2} or {|$1+$2|} or even bare {$1+$2}.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128297</commentid>
    <comment_count>1</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-12-07 18:35:10 +0000</bug_when>
    <thetext>
\{$1 + $2} looks awesome. Although you cannot set a type for $123. But types on anonymous functions  are only causing a mess with function coercion anyways





{|$1+$2|} is very bad. It is the JSONiq object merge syntax.  And the bare {$1+$2} would be confused with JSONiq object creation.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>