From 6e84331dcb063829a232ed9216422a0a3b5cad25 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 27 Jan 2022 17:13:33 -0800 Subject: [PATCH 1/2] Tighten unary op syntax and untupling language --- .../reference/changed-features/operators.md | 16 +++++++++++++--- .../other-new-features/parameter-untupling.md | 6 +++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/_docs/reference/changed-features/operators.md b/docs/_docs/reference/changed-features/operators.md index 495eb8c5ede9..9421dd45dba9 100644 --- a/docs/_docs/reference/changed-features/operators.md +++ b/docs/_docs/reference/changed-features/operators.md @@ -6,9 +6,12 @@ movedTo: https://docs.scala-lang.org/scala3/reference/changed-features/operators The rules for infix operators have changed in some parts: -First, an alphanumeric method can be used as an infix operator only if its definition carries an `infix` modifier. Second, it is recommended (but not enforced) to -augment definitions of symbolic operators with [`@targetName` annotations](../other-new-features/targetName.md). Finally, -a syntax change allows infix operators to be written on the left in a multi-line expression. +First, an alphanumeric method can be used as an infix operator only if its definition carries an `infix` modifier. + +Second, it is recommended (but not enforced) to augment definitions of symbolic operators +with [`@targetName` annotations](../other-new-features/targetName.md). + +Finally, a syntax change allows infix operators to be written on the left in a multi-line expression. ## The `infix` Modifier @@ -163,3 +166,10 @@ Another example: This code is recognized as three different statements. `???` is syntactically a symbolic identifier, but neither of its occurrences is followed by a space and a token that can start an expression. + +## Unary operators + +As a minor restriction, the first parameter list of a unary operator must not be explicit and empty. +A unary operator is a method named "unary_`op`" where `op` is one of `+`, `-`, `!`, or `~`. + +The reason for this restriction is that unary operator syntax does not support supplying an argument list, even if it is empty. diff --git a/docs/_docs/reference/other-new-features/parameter-untupling.md b/docs/_docs/reference/other-new-features/parameter-untupling.md index 84bbe52bddc1..4c0fdb2765e2 100644 --- a/docs/_docs/reference/other-new-features/parameter-untupling.md +++ b/docs/_docs/reference/other-new-features/parameter-untupling.md @@ -39,9 +39,9 @@ def combine(i: Int, j: Int) = i + j xs.map(combine) ``` -Generally, a function value with `n > 1` parameters is converted to a -pattern-matching closure using `case` if the expected type is a unary -function type of the form `((T_1, ..., T_n)) => U`. +Generally, a function value with `n > 1` parameters is wrapped in a +function type of the form `((T_1, ..., T_n)) => U` if that is the expected type. +The tuple parameter is decomposed and its elements are passed directly to the underlying function. More specifically, the adaptation is applied to the mismatching formal parameter list. In particular, the adaptation is not a conversion From 60f85f4c8fd2b70a5822b415b93c131587ad6edf Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 24 Feb 2022 22:04:09 -0800 Subject: [PATCH 2/2] Less blabbing per review --- docs/_docs/reference/changed-features/operators.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/_docs/reference/changed-features/operators.md b/docs/_docs/reference/changed-features/operators.md index 9421dd45dba9..9b4e20dadfe5 100644 --- a/docs/_docs/reference/changed-features/operators.md +++ b/docs/_docs/reference/changed-features/operators.md @@ -169,7 +169,5 @@ neither of its occurrences is followed by a space and a token that can start an ## Unary operators -As a minor restriction, the first parameter list of a unary operator must not be explicit and empty. +A unary operator must not have explicit parameter lists even if they are empty. A unary operator is a method named "unary_`op`" where `op` is one of `+`, `-`, `!`, or `~`. - -The reason for this restriction is that unary operator syntax does not support supplying an argument list, even if it is empty.