RE: Arrow operator and ParenthesizedExpr

I agree that this transformation would be a much better way to specify the semantics:

> Given a UnaryExpr U, an ArrowFunctionSpecifier F, and a ArgumentList (A, B, C…), 
> the expression U => F(A, B, C…) is equivalent to the expression F(U, A, B, C…)

Jonathan

________________________________________
From: Michael Kay [mike@saxonica.com]
Sent: Thursday, September 10, 2015 11:28 AM
To: Robie, Jonathan
Cc: Abel Braaksma; Public Joint XSLT XQuery XPath
Subject: Re: Arrow operator and ParenthesizedExpr

The language of the spec (once again) leaves a lot to the reader, but I’ve always read it as a kind of macro: (A => f(X, Y)) is translated during expression parsing to f(A, X, Y).

Syntax productions never tell you what the type rules are; the grammar doesn’t tell you that (1,2,3)(4) is a type error, nor does it tell you that 4 => (1,2,3) is a type error.

The spec could certainly be improved. Currently it’s specification-by-example, and the example is confusing if you analyse it. It says “If $s is a sequence and f() is a function”. Are we talking about expressions, or about the values of expressions? In the first case $s we are talking of the value of the expression, but in the second case f() we are talking about the expression itself; except that then f() is not a function, but a function call.

I think it would be clearer to specify it by means of a syntactic transformation:

Given a UnaryExpr U, an ArrowFunctionSpecifier F, and a ArgumentList (A, B, C…), the expression U => F(A, B, C…) is equivalent to the expression F(U, A, B, C…)

(I would get rid of some of the self-justification from the spec as well. A well-chosen example should be enough to persuade readers of the benefits of the feature. We don’t need to tell people how wonderful it is, we should let them come to that conclusion themselves.)

Michael Kay
Saxonica


> On 10 Sep 2015, at 15:51, Robie, Jonathan <jonathan.robie@emc.com> wrote:
>
> Good catch.
>
> I think it should be a type error if ArrowFunctionSpecifier evaluates to anything other than a single function.
>
> Allowing a sequence of functions makes sense too, but there are other ways to get this functionality, I don't think that's what people have implemented, and it could add some complexity to the implementation.  It might also invite queries that are harder to read ...
>
> Jonathan
> ________________________________________
> From: Abel Braaksma [abel.braaksma@xs4all.nl]
> Sent: Thursday, September 10, 2015 10:40 AM
> To: Public Joint XSLT XQuery XPath
> Subject: Arrow operator and ParenthesizedExpr
>
> If I understand the syntax productions correctly, the following is legal:
>
> let $a := concat('hello', ?)
> let $b := concat('world', ?)
> return "!" => ($a, $b)()
>
> The spec only talks of "the function" with respect to the rhs of the expression. But here it is a sequence of expressions. Likewise, if the rhs sequence evaluates to the empty sequence, is the result the empty sequence?
>
> If I were to interpret the above, assuming it is allowed, I'd say the output should be: ("hello!", "world!") (i.e., a sequence of two items, as a result of applying the arrow operator to each item in the sequence).
>
> If this is indeed legal, perhaps we can change the text to read "An arrow operator applies a sequence of functions to the value of...". If it is not legal (but legal syntax), perhaps we can say it isn't, for instance by saying that the result of evaluating ArrowFunctionSpecifier must be one-and-only-one.
>
> Cheers,
> Abel
>
>
>


Received on Thursday, 10 September 2015 15:53:27 UTC