trustedtomato / proposal-partial-expression

Function partial application, operator partial application and all that fun stuff.
10 stars 1 forks source link

Comparison with smart-pipelines proposal #8

Open js-choi opened 6 years ago

js-choi commented 6 years ago

Hi, I’m the author of a smart pipelines proposal. It has already been formally specified, it has a Babylon plugin under development, and it will be presented to the TC39 by @littledan next week alongside the original pipelines proposal and an alternative pipeline proposal.

The smart pipelines proposal has a “topic style” that is very similar to your proposal. (N-ary expressions are deferred to an “additional feature”.)

Right now I’m hurrying to help prepare the presentation and the Babel plugin for TC39, so I don’t have free time to examine your proposal in detail right now. But I will definitely take a close look at it sometime. In the meantime, I would love to hear your response to the similarity between our proposals. 👍

trustedtomato commented 6 years ago

I rewrited some of your "topic style" examples using this proposal & the original pipeline proposal.

Your example... ...could be rewritten as
```javascript promise |> await # |> # || throw new TypeError( `Invalid value from ${#}`) |> doubleSay(#, ', ') |> capitalize(#) |> # + '!' |> new User.Message(#) |> await stream.write(#) ``` ```javascript promise |> #await ? // diff1: the syntactic marker is needed |> #?0 || throw new TypeError( `Invalid value from ${?0}`) // diff2: 0 is needed in ?0 |> #doubleSay(?, ', ') |> capitalize // note1: there is no need to invoke the function |> #? + '!' |> #new User.Message(?) |> #await stream.write(?) ```
```javascript 5 |> # - 3 |> -# |> # * 2 |> Math.max(#, 0) ``` ```javascript 5 |> #? - 3 |> #-? |> #? * 2 |> #Math.max(?, 0) ```

To remove those differences, some addition rules are needed.

Solution1

Using these rules, my rewritten examples could be:

Your example... ...could be rewritten as
```javascript promise |> await # |> # || throw new TypeError( `Invalid value from ${#}`) |> doubleSay(#, ', ') |> capitalize(#) |> # + '!' |> new User.Message(#) |> await stream.write(#) ``` ```javascript promise |> await ? |> ? || throw new TypeError( `Invalid value from ${?}`) |> doubleSay(?, ', ') |> capitalize |> ? + '!' |> new User.Message(?) |> await stream.write(?) ```
```javascript 5 |> # - 3 |> -# |> # * 2 |> Math.max(#, 0) ``` ```javascript 5 |> ? - 3 |> -? |> ? * 2 |> Math.max(?, 0) ```

Problems

Solution2

Problems

Solution3

Same as Solution2, but the |> is interpreted as |>#. This would resolve all differences.

Problems

Conclusion

Afterall, I don't think the original translations are too different, so keeping it as is would not be too bad. But if you do, I think Solution3 is the most versatile one. Let me know what you think!