Repository navigation
Conversation
2e3c4e8 to
8407062
Compare
|
In my opinion, the proposed syntax is rather less readable than the current closures syntax, but okay: 👍 |
There was a problem hiding this comment.
Is it possible to export this to another function? Growing and growing existing functions is a path to nightmare.
There was a problem hiding this comment.
yes, this is a simple independent branch which could be easily exported. But these really aren't the issue, but rather when you have interdependent branches...
There was a problem hiding this comment.
Is it an excuse to not export this one? :-)
|
What a brilliant feature! Please merge it into 7.0. |
|
Well Hack/HHVM uses '==>', why doesnt PHP use the same operator then? |
|
See RFC |
|
I understand the fact that ==> may look more similar to array syntax =>, this is logical. But why is it better if PHP uses its own syntax? To me its better if PHP and Hack use the same syntax, and code will be easier to port between the two languages. Not mentioning, in PHP 8 or PHP 9, PHP and Hack may become one language. |
|
It's really exciting that this feature is in the pipeline! There is a little more cognitive load on the PHP/Hack community (considered as a whole) by having two syntaxes for the same feature. The comment from @sgolemon is "Also, after much discussion, we'd probably prefer if PHP used its own syntax. Then we can keep ==> as we like it." I'd like to know what possible differences could arise between Hack's and PHP's implementation of this feature that would necessitate that the syntaxes be different. My understanding is that they both desugar to a regular |
|
==> is not confusing at all, everybody knows that => has only one = symbol. Did you consider --> and =>>? |
|
~> is hardly legible on high resolution screens. |
|
The symbol is more accentuated on monospaced fonts |
4fec999 to
30e3691
Compare
|
What was the problem to create an RFC voting for both variants '==>' and '~>'? - cause now it seems that this good RFC will be burried among declined ones and we'll have to wait again for another proposal. |
|
We'll have another proposal, by @morrisonlevi ;-) [based on this patch, just altered a bit] But as we're not in hurry, just one proposal after the other. |
|
Closing as the RFC was declined, at least for now. |
|
R.I.P |
|
Really this is more readable and logical: And very standard in programming languages. And besides "~" is used in github markup. |
|
We're looking forward to being accepted in PHP 8 as an improved version... |
|
I like short syntax (like arrow functions in ECMA) |
|
@kakserpom |
|
Please add short Closure feature,from long time waiting... var multiply_result = (x, y) => x*y; // IN ES6 $multiply_result = (x, y) <= x*y; // IN My PHP $multiply_result = (x, y) <> x*y; // IN My PHP $multiply_result = (x, y) <=> x*y; // IN My PHP // Why already have <=> it is not that much readable. |
|
it could be more python-styled like $result = lambda $x : $x*2; |
|
Better idea in the title of this pull request. Short syntax, too few chars... "~>" is better variant. Like JS, C#, but in one's own way. |
|
@DAVIDhaker Yes, I'm really confused and I don't understand why the original |
|
Better use default |
|
For [
$foo => $bar,
]Does it defines an array with an item with key For $foo->$barDoes it defines a short closure that takes |
|
|
|
I dont know why you write that Code sample for example: Additional suggestion: in one line statement ';' and 'return' is not required. |
|
Why not just use parentheses to solve the issues mentioned here, as suggested by @ssipos90? Array value [
// key/val
($x) => $x * 2,
// func val
(($x) => $x * 2),
// key/func
($x) => ($x) => $x * 2 // parens around func optional, only required for non-keyed values
]Yield // yield key/val
yield ($x) => $x * 2;
// yield func
yield (($x) => $x * 2);Then you can use braces for multi-statement function bodies, as in other languages. |
|
This is not the place to discuss syntax questions -- if you'd like to restart the conversation on short lambda syntax, please write to the PHP internals mailing list. Please further note that this topic has already been discussed quite extensively, and unless you are familiar with LALR(1) parser limitations, your suggestions will likely not be technically feasible (or you need to expand on the implementation tradeoffs you wish to make). |
Implementation for https://wiki.php.net/rfc/short_closures