[xquery-talk] arrow operator
gfourny at inf.ethz.ch
Wed Aug 2 03:00:23 PDT 2017
There is one more important difference on the syntactic level.
With the arrow operator, the left-hand-side is implicitly bound to the first parameter of the function.
@address => replace(@postcode, "", "q")
is the same as
replace(@address, @postcode, "", "q")
With the simple map operator, the context item must be explicitly referred to, like so:
@address ! replace(., @postcode, "", "q")
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.
For example :
@address ! string(.) (: explicitly passed context item :)
@address ! string() (: context item passed implicitly to string#0, which is context-dependent)
@address => string() (: context item passed implicitly to string#1 via the => operator, but string#1 is context-independent)
I hope I got it right!
> On 2 Aug 2017, at 11:27, W.S. Hager <wshager at gmail.com> wrote:
> Hi Michael,
> 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?
> Op 1 aug. 2017 18:58 schreef "Michael Kay" <mike at saxonica.com>:
> 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.
> Also, of course, "!" changes the context item, so
> @address => replace(@postcode, "", "q") works, while
> @address ! replace(@postcode, "", "q") doesn't.
> Michael Kay
> > On 1 Aug 2017, at 13:27, W.S. Hager <wshager at gmail.com> wrote:
> > Hi,
> > Is there any advantage to using the 3.1 arrow operator over the simple map operator?
> > $string => upper-case() => normalize-unicode() => tokenize("\s+")
> > versus
> > $string ! upper-case(.) ! normalize-unicode(.) ! tokenize(.,"\s+")
> > Thanks,
> > Wouter
> > _______________________________________________
> > talk at x-query.com
> > http://x-query.com/mailman/listinfo/talk
> talk at x-query.com
More information about the talk