Req #66368 [Com]: Operators should also be functions

From: Date: Sun, 13 Feb 2022 02:33:31 +0000
Subject: Req #66368 [Com]: Operators should also be functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239717@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66368&edit=1 ID: 66368 Comment by: master dot training365 at gmail dot com Reported by: chriswarbo at gmail dot com Summary: Operators should also be functions Status: Assigned Type: Feature/Change Request Package: *General Issues Operating System: Irrelevant PHP Version: Irrelevant Assigned To: ajf Block user comment: N Private report: N New Comment: http://glintpost.pbworks.com/w/page/147976458/FrontPage Previous Comments: ------------------------------------------------------------------------ [2022-02-13 02:03:12] master dot training365 at gmail dot com https://pastelink.net/sd8e3bqt ------------------------------------------------------------------------ [2022-02-13 01:57:21] master dot training365 at gmail dot com http://git.province.namur.be/Wikiew/Techi/wiki/Creat5 ------------------------------------------------------------------------ [2017-09-12 13:52:28] cmb@php.net FTR: a respective "Operator functions" RFC is currently under discussion: <https://wiki.php.net/rfc/operator_functions>. ------------------------------------------------------------------------ [2014-01-02 12:23:24] chriswarbo at gmail dot com It is sufficient to do: $o = function($l, $r) { return $l + $r; }; But after defining such a function for the umpteenth time, I decided to raise this issue. I don't think I'm alone in using such definitions, since it's a common-enough pattern that we had array_sum built in to the language even before we had lambdas and array_reduce (array_sum is just array_reduce curried with $o and 0). One solution would be to build in functions like $o to prevent the need to define them over and over in-line or in libraries, but I'd rather not be 'that guy' who wants his own helper-functions built-in, since adding new functions bloats the language and, more importantly, burdens developers with extra complexity ("Should I use + or $o?"). Instead, I think it's an opportunity to fix the treatment of operators, especially since functions like $o are just eta-expansions of operators, and eta-expansion is always a useless transformation: function eta($f) { return function ($x) { return $f($x); }; } call_user_func(eta($x), $y) === call_user_func($x, $y) ------------------------------------------------------------------------ [2014-01-01 14:43:23] krakjoe@php.net Ok, I understand a bit clearer what you're asking for ... but don't really see why; I cannot imagine a time where: $o = '+'; $o(10, 20); Is required such that: $o = function($l, $r) { return $l + $r; }; Does not suffice. Maybe someone else will get it, I don't ... ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=66368 -- Edit this bug report at https://bugs.php.net/bug.php?id=66368&edit=1

« previous php.bugs (#239717) next »