<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Dear Wouter,
<div class=""><br class="">
</div>
<div class="">I see your point and it makes sense. The tricky part here, following up on your suggestion to make the choice of the first position less arbitrary, is that the context item must be an item: it cannot be a sequence of several items. This eliminates
 any design based on communicating the value on the left through the context item mechanism. The closest to the intent of => would be using a let variable binding.</div>
<div class=""><br class="">
</div>
<div class="">The convention of binding the first argument, of course, implies that the (or some) functions are designed having in mind that the first parameter is “special”, that is, if the function is intended to be used with =>. In Java or C++, the self/this
 implied parameter is special, too (but it is not considered to be at any position).</div>
<div class=""><br class="">
</div>
<div class="">Kind regards,</div>
<div class="">Ghislain</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 2 Aug 2017, at 16:22, W.S. Hager <<a href="mailto:wshager@gmail.com" class="">wshager@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">To be precise, I think it means that the context needs to be bound to the result of the left side of the arrow, but perhaps that isn't even possible. Anyway, the convention seems to me just as trivial as binding the first argument.
<div class=""><br class="">
</div>
<div class=""><br class="">
<div class="gmail_extra"><br class="">
<div class="gmail_quote">2017-08-02 16:17 GMT+02:00 W.S. Hager <span dir="ltr" class="">
<<a href="mailto:wshager@gmail.com" target="_blank" class="">wshager@gmail.com</a>></span>:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="">
<div class="">Dear Ghislain,</div>
<div class=""><br class="">
</div>
This I understand, but the only thing that bothers me is that the implicit binding of the first argument prevents the use of other arguments, whereas an explicit context would've allowed for the more flexible option of designating the argument yourself, while
 the arity would read more clearly:
<div class=""><br class="">
</div>
<div class="">$position => array:remove($array, .)</div>
<div class=""><br class="">
</div>
<div class="">This difference with the simple mapping operator is what confuses and surprises me, but it seems I'm the only one, so let's just leave it at that.</div>
<div class=""><br class="">
</div>
<div class="">Thanks a lot for your time.</div>
<div class=""><br class="">
</div>
<div class="">Wouter
<div class="">
<div class="h5"><br class="">
<div class="gmail_extra"><br class="">
<div class="gmail_quote">2017-08-02 16:08 GMT+02:00 Ghislain Fourny <span dir="ltr" class="">
<<a href="mailto:gfourny@inf.ethz.ch" target="_blank" class="">gfourny@inf.ethz.ch</a>></span>:<br class="">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Dear Wouter,<br class="">
<br class="">
Indeed, in some cases, whether to use => or ! can be subject to a matter of taste.<br class="">
<br class="">
To put things in perspective, => was introduced in version 3.1, together with map and array support. As far as I understand it and looking again at the specs, one of the use cases is for => to be used with maps and arrays, in an object-oriented style. The XPath
 and XQuery Functions and Operators 3.1 specification [1] explicitly gives a few examples:<br class="">
<br class="">
["a", "b", "c"] => array:get(2)<br class="">
<br class="">
$array => array:remove($position) => array:insert-before($position, $member)<br class="">
<br class="">
Kind regards,<br class="">
Ghislain<br class="">
<br class="">
[1] <a href="https://www.w3.org/TR/xpath-functions-31/" rel="noreferrer" target="_blank" class="">
https://www.w3.org/TR/xpath-fu<wbr class="">nctions-31/</a><br class="">
<div class="m_8617771463208286267gmail-HOEnZb">
<div class="m_8617771463208286267gmail-h5"><br class="">
<br class="">
> On 2 Aug 2017, at 12:09, W.S. Hager <<a href="mailto:wshager@gmail.com" target="_blank" class="">wshager@gmail.com</a>> wrote:<br class="">
><br class="">
> That's why, for cases where it's possible, I preferred to write the simple mapping operator, as it's easier to read IMO.<br class="">
><br class="">
> 2017-08-02 12:07 GMT+02:00 W.S. Hager <<a href="mailto:wshager@gmail.com" target="_blank" class="">wshager@gmail.com</a>>:<br class="">
> Hi Ghislain,<br class="">
><br class="">
> Alright, I forgot about fn:replace#4, but the implicit binding is sometimes hard to detect.<br class="">
><br class="">
> Thanks.<br class="">
><br class="">
><br class="">
> 2017-08-02 12:04 GMT+02:00 Ghislain Fourny <<a href="mailto:gfourny@inf.ethz.ch" target="_blank" class="">gfourny@inf.ethz.ch</a>>:<br class="">
> ... I didn't get it quite right actually. In @address => string(), there is no context item involved, I wrote too fast. :-)<br class="">
><br class="">
> New attempt:<br class="">
><br class="">
> @address ! string(.) (: explicitly passed context item :)<br class="">
> @address ! string() (: context item passed implicitly to string#0, which is context-dependent)<br class="">
> @address => string() (: @address passed implicitly to string#1 as the first parameter via the => operator, but string#1 is context-independent)<br class="">
> @address => string(.) (: error: string#2 does not exist :)<br class="">
><br class="">
> Kind regards,<br class="">
> Ghislain<br class="">
><br class="">
><br class="">
> > On 2 Aug 2017, at 12:00, Ghislain Fourny <<a href="mailto:gfourny@inf.ethz.ch" target="_blank" class="">gfourny@inf.ethz.ch</a>> wrote:<br class="">
> ><br class="">
> > Dear Wouter,<br class="">
> ><br class="">
> > There is one more important difference on the syntactic level.<br class="">
> ><br class="">
> > With the arrow operator, the left-hand-side is implicitly bound to the first parameter of the function.<br class="">
> ><br class="">
> > @address => replace(@postcode, "", "q")<br class="">
> ><br class="">
> > is the same as<br class="">
> ><br class="">
> > replace(@address, @postcode, "", "q")<br class="">
> ><br class="">
> ><br class="">
> > With the simple map operator, the context item must be explicitly referred to, like so:<br class="">
> ><br class="">
> > @address ! replace(., @postcode, "", "q")<br class="">
> ><br class="">
> ><br class="">
> > What may create confusion is that some functions have several signatures, some of which implicitly refer to the context item. But this is a very different mechanism.<br class="">
> ><br class="">
> > For example :<br class="">
> ><br class="">
> > @address ! string(.) (: explicitly passed context item :)<br class="">
> > @address ! string() (: context item passed implicitly to string#0, which is context-dependent)<br class="">
> > @address => string() (: context item passed implicitly to string#1 via the => operator, but string#1 is context-independent)<br class="">
> ><br class="">
> > I hope I got it right!<br class="">
> ><br class="">
> > Kind regards,<br class="">
> > Ghislain<br class="">
> ><br class="">
> ><br class="">
> >> On 2 Aug 2017, at 11:27, W.S. Hager <<a href="mailto:wshager@gmail.com" target="_blank" class="">wshager@gmail.com</a>> wrote:<br class="">
> >><br class="">
> >> Hi Michael,<br class="">
> >><br class="">
> >> The way you used the arrow operator in the example would be the way I expected it to work, namely by explicitly addressing the context, but it seems that it doesn't. It's actually implicitly binding the first argument of the function on the right to the
 value on the left. Or is there an exception I don't know about?<br class="">
> >><br class="">
> >> Thanks.<br class="">
> >><br class="">
> >> Op 1 aug. 2017 18:58 schreef "Michael Kay" <<a href="mailto:mike@saxonica.com" target="_blank" class="">mike@saxonica.com</a>>:<br class="">
> >> In the case of singletons there's very little difference, but (as I now see Christian has pointed out), with sequences the effect is quite different.<br class="">
> >><br class="">
> >> Also, of course, "!" changes the context item, so<br class="">
> >><br class="">
> >> @address => replace(@postcode, "", "q") works, while<br class="">
> >><br class="">
> >> @address ! replace(@postcode, "", "q") doesn't.<br class="">
> >><br class="">
> >> Michael Kay<br class="">
> >> Saxonica<br class="">
> >><br class="">
> >>> On 1 Aug 2017, at 13:27, W.S. Hager <<a href="mailto:wshager@gmail.com" target="_blank" class="">wshager@gmail.com</a>> wrote:<br class="">
> >>><br class="">
> >>> Hi,<br class="">
> >>><br class="">
> >>> Is there any advantage to using the 3.1 arrow operator over the simple map operator?<br class="">
> >>><br class="">
> >>> $string => upper-case() => normalize-unicode() => tokenize("\s+")<br class="">
> >>><br class="">
> >>> versus<br class="">
> >>><br class="">
> >>> $string ! upper-case(.) ! normalize-unicode(.) ! tokenize(.,"\s+")<br class="">
> >>><br class="">
> >>> Thanks,<br class="">
> >>> Wouter<br class="">
> >>> ______________________________<wbr class="">_________________<br class="">
> >>> <a href="mailto:talk@x-query.com" target="_blank" class="">talk@x-query.com</a><br class="">
> >>> <a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer" target="_blank" class="">
http://x-query.com/mailman/lis<wbr class="">tinfo/talk</a><br class="">
> >><br class="">
> >><br class="">
> >> ______________________________<wbr class="">_________________<br class="">
> >> <a href="mailto:talk@x-query.com" target="_blank" class="">talk@x-query.com</a><br class="">
> >> <a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer" target="_blank" class="">
http://x-query.com/mailman/lis<wbr class="">tinfo/talk</a><br class="">
> ><br class="">
><br class="">
><br class="">
><br class="">
><br class="">
><br class="">
><br class="">
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
<div class="m_8617771463208286267gmail_signature">
<div class="">
<p class=""><br class="">
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
<div class="gmail_signature" data-smartmail="gmail_signature">
<div class="">
<p class=""><br class="">
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>