On 22/07/2016 06:52, Sara Golemon wrote:
Ah! I understand your point now.  Indeed, in terms of code-scan,
there's something of a whiplash effect going on. Now I understand the
motivation behind $> assignment and/or using a terminal like `return
$$` at the end.

Adding in support for some terminals (like return) could make sense,
it's an exception to a rule, but it's a reasonable looking one (at
first glance, anyway).

Glad it makes sense. :) I realise "return $$" would have to have some special handling, but it would feel more natural to me. I guess the only concern is what happens when a pipeline has a return terminal and is used in expression context:

$foo = bar() |> baz($$) |> return $$;
// theoretically translates to this invalid PHP:
$foo = return baz(bar());

I'm not sure how easily the compiler would be able to pick up that that's an illegal construction.


I was going to say that "yield" would be worth considering at the same time, but presumably that's already legal, because yield can appear as an expression (to receive variables sent into a co-routine).

It's a shame neither "echo" nor "print" is useful for getting $$ out to screen and leaving it unchanged (echo doesn't work in expression context at all; print doesn't have a useful return value).


The assign to var at the end however, is something I'd rather handle
with the following:

foo() |> bar($$) |> $baz = qux($$);

Which is both legal with the syntax as-is, and entirely readable
without adding an extra operator.

Yes, on reflection I think "|> $foo = $$" is probably easier to follow than extra syntax. I quite like the idea of a whole language where data always flows left-to-right, but we're used to that being what assignment looks like.

It might be worth coming up with some examples to add to the RFC where $$ is used in an expression other than a function call, because I wasn't entirely sure when I read it if that was even allowed. It might also clear up some of the confusion around this being anything to do with OO.

Off the top of my head, how about some maths:

$foo * $bar
    |> 2 ** $$
    |> sin($$ + 1)
    |> $$ / 20
    |> $result = $$;

Compiles to:

$result = sin((2 ** ($foo * $bar)) + 1) / 20;

Or:

$temp = $foo * $bar;
$temp = 2 ** $temp;
$temp = sin($temp + 1);
$result = $temp / 20;

Regards,

--
Rowan Collins
[IMSoP]


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

Reply via email to