Skip to content

Commit

Permalink
Address feedback from Richard
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ-Johnson committed Jun 3, 2024
1 parent 4b408a2 commit 2460c5f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions proposals/p3848.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ fn Foo() {

### Succinctly

Function definitions have one of the following syntactic forms (where items in
square brackets are optional and independent):
Function definitions and lambda expressions have one of the following syntactic
forms (where items in square brackets are optional and independent):

`fn` \[_name_\] \[_implicit-parameters_\] \[_tuple-pattern_\] `=>` _expression_
`;`
\[`;`\]

`fn` \[_name_\] \[_implicit-parameters_\] \[_tuple-pattern_\] \[`->`
_return-type_\] `{` _statements_ `}`
Expand All @@ -155,7 +155,8 @@ first; the other items can appear in any order. If _implicit-parameters_ is
omitted, it is equivalent to `[]`.

The presence of _name_ determines whether this is a function declaration or a
lambda expression.
lambda expression. The trailing `;` in the first form is required for a function
declaration, but is not part of the syntax of a lambda expression.

The presence of _tuple-pattern_ determines whether the function body uses named
or positional parameters.
Expand Down Expand Up @@ -468,6 +469,12 @@ fn Example {
}
```

Note: If a function object F has mutable state, either because it has a
non-const copy capture or because it has a by-object function field, then a call
to F should require the callee to be a reference expression rather than a value
expression. We need a mutable handle to the function in order to be able to
mutate its mutable state.

#### Alternative Considered: By-Value Captures

Alternatively, the below-shown four capture modes (by-value, by-object, by-copy
Expand Down Expand Up @@ -605,9 +612,9 @@ if the underlying type is not copyable, the reference to that object is always
copyable.

The final case is by-value function fields. Since C++ const references, when
made into fields of a class, prevent the class from being copied, so too should
by-value function fields prevent the function in which it is contained from
being copied.
made into fields of a class, prevent the class from being copied assigned, so
too should by-value function fields prevent the function in which it is
contained from being copied assigned.

## Self and Recursion

Expand All @@ -617,6 +624,13 @@ For function declarations, it is only permitted when the function is a member of
a class type, such that it refers to the class type and not to the function
itself.

Note: Given the direction in
[#3720](https://github.com/carbon-language/carbon-lang/pull/3720), an expression
of the form `x.(F)`, where `F` is a function with a `self` or `addr self`
parameter, produces a callable that holds the value of `x`, and does not hold
the value of `F`. As a consequence, we can't support combining captures and
function fields with a `self` parameter.

### Alternative Considered: Recursive Self

For use in recursion, `self: Self` could be permitted on all functions and
Expand Down

0 comments on commit 2460c5f

Please sign in to comment.