Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison with smart-pipelines proposal #8

Open
js-choi opened this issue Mar 15, 2018 · 1 comment
Open

Comparison with smart-pipelines proposal #8

js-choi opened this issue Mar 15, 2018 · 1 comment

Comments

@js-choi
Copy link

js-choi commented Mar 15, 2018

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
Copy link
Owner

trustedtomato commented Mar 15, 2018

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

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

To remove those differences, some addition rules are needed.

Solution1

  • to resolve diff1: The pipeline automatically creates an #… expression if the pipeline includes a ?.
  • to resolve diff2: In this expression, all of the ?s point to the same argument.

Using these rules, my rewritten examples could be:

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

Problems

  • I don't think its a good idea to remove the syntactic marker though due to the garden path problem.

Solution2

  • to resolve diff2: recognize the |># pattern and point all of the ?s to the same argument.

Problems

  • diff1 is not resolved.

Solution3

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

Problems

  • note1 would be "destroyed": 'hello' |> capitalize would be translated to 'hello' |> x => capitalize instead of 'hello |> x => capitalize(x)'.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants