On Fri, Mar 10, 2023 at 10:56 PM Christian Schneider
<cschn...@cschneid.com> wrote:
>
> Am 10.03.2023 um 20:04 schrieb Eugene Sidelnyk <zsidel...@gmail.com>:
> > Another simplified example:
> >
> > ```
> > // partial application
> > foo(bar(1, ...));
>
> While it is not as concise as your version I think the work-around with short 
> arrow functions works ok unless your code is full of partial applications:
>         foo(fn(...$a) =>  bar(1, ...$a));
>
> Regards,
> - Chris
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
Hey Eugene

I actually started on an implementation with this exact syntax this
past summer. I stopped after seeing the RFC was already declined years
ago. However, there are still some tricky parts to work out. Right
now, the "first-class callable" gets (basically) turned into a
callable string at the first possible instant, just after parsing.
This has to be thrown away, or handled in some other way. In my
implementation, I went with treating that as a special case, and
basically considering the partial application as 'syntax sugar'. There
are also other issues with the grammar, which I'll get to in a few
minutes.

My "syntax sugar" implementation was that this:

return $this->cache->get($command->getPhone(), $this->storeOtp($command, ...));

gets turned into this:

return fn(...$x) => $this-cache->get($command->getPhone(),
$this->storeOtp($command, ...$x));

There were a number of edge cases to solve, but I stopped
implementation before I got there.

The biggest issue was that the grammar became a little bit ambiguous.
I'm sure someone smarter than me can figure out how to define the
grammar in a way that isn't ambiguous... but the gist is that the
triple-dot is also used for array unpacking, thus I ended up disabling
that code path to get it to work.

I can probably clean up my code and submit a PR, if anyone would be interested.

Cheers,

Rob

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to