Re: Introduce the abiltiy to use the first-call-callable syntax on non-static methods, statically
| From: | Robert Landers | Date: | Mon, 23 Jan 2023 18:22:43 +0000 |
| Subject: | Re: Introduce the abiltiy to use the first-call-callable syntax on non-static methods, statically | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119405@lists.php.net to get a copy of this message | ||
On Mon, Jan 23, 2023 at 6:31 PM Larry Garfield <larry@garfieldtech.com> wrote:
>
> On Mon, Jan 23, 2023, at 10:53 AM, Ollie Read wrote:
> > There's definitely similarity, but I would say it sits somewhere
> > between the two. Rather than reference a partial method call, or create
> > a closure for a method, you're delaying a method call. Or rather,
> > referencing a method. We have the ::class pseudo property, so I see
> > this like an equivalent, but for methods.
>
> So what you're really looking for is a shorter way to write this:
>
> foo(fn(Str $s) => $s->beep());
>
> Now you're definitely in the realm of PFA, pipes, and that kind of functionality. And,
> sadly, Internals has shown a great deal of resistance to that kind of functionality. I have a
> user-space implementation of pipes that includes utilities to do something similar[1], but most
> functional languages I know also don't have a really strong native way to "turn
> around" a call like that.
>
> I'd love a solution for that, but so far it has proven both elusive and controversial.
>
> --Larry Garfield
>
> [1] https://github.com/Crell/fp/blob/master/src/object.php#L28
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
Speaking of partial application, it'd be amazing if it were available
with the current closure syntax:
$func = fn($x, $y, $z) => echo $x + $y + $z;
$plus1 = $func(..., 1);
$plus2n1 = $func(2, 1, ...);
$a = $plus1(1, 2);
$b = $plus2n1(5);
I spent a few days last summer trying this out, but couldn't get the
grammar parser to accept it. I think I have a local branch if someone
would be willing to work on it with me. At least point me in the right
direction. I don't have much free time these days, but it is certainly
doable.
Robert Landers
Software Engineer
Utrecht NL