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

Alternative syntax #373

Open
tshemsedinov opened this issue Sep 1, 2018 · 8 comments
Open

Alternative syntax #373

tshemsedinov opened this issue Sep 1, 2018 · 8 comments
Assignees

Comments

@tshemsedinov
Copy link
Member

Syntax idea by @primeare, modifications by @tshemsedinov

const { μ } = require('metasync');
const f = μ(f1)(f2, μ(f3)(f4), f5)(f6);
f((err, result) => {
  console.dir(err, result);
});

Known problems:

  • How can we compose sequential inside parallel composition? Solved: μ(f3)(f4) in example.
  • We can't distinguish sequential composition and composed function call. So when we will start execution?
@lundibundi
Copy link
Member

I don't like the idea of using utf8 symbol you can't easily write from the keyboard and have to copy paste (μ).
As for the syntax, I find just using arrays much clearer as to what's going on. This syntax is cluttered with parentheses that hide the actual meaning too much imo.
Perhaps at least:

const { seq, par } = require('metasync');
const f = seq(f1, par(f2, seq(f3, f4), f5), f6);
f((err, result) => {
  console.dir(err, result);
});

@tshemsedinov
Copy link
Member Author

I saved proposal from @primeare here just for notes, @lundibundi
We have no solution to distinguish sequential composition and composed function call, because f have a same contract with f6, so should we compose or start execution on next (). But maybe it will be used in future or will give inspiration to someone.

@tshemsedinov
Copy link
Member Author

@lundibundi I like arrays too, because it all other syntax will finally save calls to data structures (most likely those arrays) and then will iterate executing seq/par. Arrays are enough expressive so no need to build arrays implicitly.

@aqrln
Copy link
Member

aqrln commented Sep 3, 2018

@lundibundi

I don't like the idea of using utf8 symbol you can't easily write from the keyboard and have to copy paste (μ).

FWIW, even if you don't setup AltGr or whatever it's called on your system (which you probably do, because you can't even enter em-dashes (—) from the keyboard otherwise; on Macs, for example, it is set up by default, so µ is just Option+m), you can enable Greek input method and enter µ as switch to Greek, m, switch back to English.

I agree that a non-ASCII name shouldn't be the only one for a function, but a convenient Unicode alias does sound like a good idea to me.

@lundibundi
Copy link
Member

Well, if it's an alias I'm fine. I don't want a unicode symbol to be the only way of accessing the function.

@tshemsedinov
Copy link
Member Author

@primeare why [2, 3] ? What does it mean? All returning from μ functions will have callback-last contract and all callbacks will have error-first.

@tshemsedinov
Copy link
Member Author

Do you mead μ(f1) will return single-argument function (callback) => () like this?

@tshemsedinov
Copy link
Member Author

@primeare please prepare PR so we can test it in CI and compare with current implementation syntactically and by performance.

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

No branches or pull requests

4 participants