ircmaxell / prerano

A new language for PHP
Apache License 2.0
65 stars 1 forks source link

Pipe operator #2

Closed rkrx closed 7 years ago

rkrx commented 7 years ago

Implement a pipe operator like in elixir.

Language symbol |> may differ.

'1, 2, 3, 4' |> explode(',') |> map(n => trim(n)) |> each(n => printf("#%s\n", n)
$customers = getRecentPlattformOrderIds(...)
             |> map(orderId => orderId |> fetchPlattformOrder())
             |> map(order => order |> convertPlattformOrder())
             |> filter(order => order |> getPaymentStatus() |> isPaid())
             |> each(order => order |> dbStore())
ircmaxell commented 7 years ago

What would the behavior be? Prepend the first argument only? How would it know which argument should be pipled into (I'm ok with saying only first argument, just should be explicit).

rkrx commented 7 years ago

Yes, I would say so.

All signatures of functions and methods are expected to have a reasonable parameter-order. Always having a pipable parameter at a specific position makes it easier and more fluent to use a language in other situations as well, as this could be used as a mnemonic.

ircmaxell commented 7 years ago

Implemented!

rkrx commented 7 years ago

How did you priorize the precedence rules in the praser?

For example: What happens if I write something like 2 + 3 |> mul(3)? Will this translate to mul(2 + 3, 3) or 2 + mul(3, 3)?

ircmaxell commented 7 years ago

Currently, it has a quite high precedence. Meaning that 2 + 3 |> mul(3) is interpreted as 2 + mul(3, 3).

But overall need to take a pass at precedence overall, just kinda making it work for now...