rfc:short-functions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:short-functions [2021/03/01 18:43] – Update related RFCs for more supporting evidence. crell | rfc:short-functions [2021/03/26 14:13] – crell | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2020-10-20 | * Date: 2020-10-20 | ||
* Author: Larry Garfield (larry@garfieldtech.com) | * Author: Larry Garfield (larry@garfieldtech.com) | ||
- | * Status: | + | * Status: |
- | * First Published at: http:// | + | * First Published at: http:// |
===== Introduction ===== | ===== Introduction ===== | ||
Line 19: | Line 19: | ||
function add(int $a, int $b): int | function add(int $a, int $b): int | ||
{ | { | ||
- | return $a + b; | + | return $a + $b; |
} | } | ||
</ | </ | ||
Line 48: | Line 48: | ||
Functions are simpler than lambdas, as there is no need for closing over variables contextually. | Functions are simpler than lambdas, as there is no need for closing over variables contextually. | ||
+ | ==== Consistency with closure syntax ==== | ||
+ | |||
+ | This RFC is designed to complement the [[rfc: | ||
+ | |||
+ | |||
+ | * The '' | ||
+ | * '' | ||
+ | * The '' | ||
+ | * The '' | ||
+ | * A function with a name is declared globally at compile time. A function without a name is declared locally as a closure at runtime. | ||
+ | |||
+ | These rules are easily recognizable and learnable by developers. | ||
+ | |||
+ | (Further discussion of the possible permutations, | ||
==== Reasoning ==== | ==== Reasoning ==== | ||
Line 64: | Line 78: | ||
function fullName(string $first, string $last): string | function fullName(string $first, string $last): string | ||
- | => sprintf(' | + | => sprintf(' |
</ | </ | ||
Line 397: | Line 411: | ||
The => operator has de facto become the "maps to this expression" | The => operator has de facto become the "maps to this expression" | ||
- | The author favors using " | + | The use of the '' |
- | + | ||
- | As of this time, this RFC is to use "function" for short named functions. | + | |
==== Related RFCs ==== | ==== Related RFCs ==== | ||
Line 445: | Line 457: | ||
public function withY($y): static => clone($this) with {y: $y}; | public function withY($y): static => clone($this) with {y: $y}; | ||
} | } | ||
+ | </ | ||
Thus making many cases of wither methods just as trivial to write as getter methods. | Thus making many cases of wither methods just as trivial to write as getter methods. | ||
- | |||
- | </ | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 469: | Line 480: | ||
[[https:// | [[https:// | ||
- | |||
- | [[https:// | ||
- | |||
- | Pull request for the spec still to come. | ||
===== Implementation ===== | ===== Implementation ===== |
rfc/short-functions.txt · Last modified: 2021/06/15 22:29 by ilutov