-
Notifications
You must be signed in to change notification settings - Fork 238
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
The block parameter syntax ("|x|") might be misinterpreted as "a pipe through x"? #25
Comments
👍 for Alt. 4! Heres another idea:
|
I agree, I think it's a lot more clear without |
👍 for Alternatives 2 & 5 |
I vote 1 & 3 On Mon, Dec 15, 2014 at 4:34 PM, Hugh Francis [email protected]
|
I don't understand the { |x| ... } syntax. Should we understand this to be an anonymous (stream-oriented) function? If so, the syntax for function definition, anonymous function definition, and this example should be harmonized. |
3 is the most ruby-like among the alternatives. I like it. |
I feel same way, and agree to change. But I am afraid that alternatives in OP cause shift/reduce conflict. I am thinking of FYI, |
If |
you can assign using |
@acangiano why are we trying to be like Ruby? Sure, Matz designed ruby, but that doesn't mean everything that has anything to do with him should look like Ruby. Also, I am in favor of keeping the
That seems still in keeping with most other languages, (including CoffeeScript and ES6), and wouldn't lead to any shift/reduce conflicts. Also, I do thing that #26 would be something to think about as far as shorthand for transforming and filtering streams. |
What about simplifying the syntax further and introducing shorthand argument names Alternative 7.
Reasoning:
In cases where argument names are needed for readability the syntax would be a slightly modified version of alternative 3 above to avoid the shift/reduce conflict that @matz mentioned in his comment: Alternative 8.
Reasoning:
So I suggest to allow for BOTH alternative #7 and alternative #8 depending on if named arguments are required or not :-) |
I like the haskell-like lambda syntax:
Of course if currying is good supported, If a block is wanted, we could take
Probably alternative #9? Actually it's just similar to alternative #5. |
I don‘t like (arg) to be outside of the {…}.
It looks like a num divided by a function!
|
@Krysl please edit your comment to mark your code as a code block to make it more readable |
I like alternative 3 |
👍 alternative 5 |
seq(100) | #(x) { |
seq(100) | #{
| Odd --> f = x
| Even --> b = x
} | print |
Perhaps the closure parameter can be omitted when there is only one argument |
Alternative 7 can be implemented alongside any other block parameter syntax for when no block parameters are explicitly declared, kind of like Clojure's compact lambda syntax. It would be nice for one-liners. The downside is that it makes a class of typos hard to detect, e.g., if you type |
👍 Alternative 7 & 5 together. Like in Clojure. |
I liked @tbodt's idea of creating a table of votes in #24, so I'll add one for the alternatives here:
Last updated: this comment. Sorry if I excluded anyone, I tried to only include votes that were more explicit, and only alternatives that were numbered to make things simpler. |
By the way, in the future, it might be easier to use some sort of wiki and/or poll site to organize alternative ideas. http://poll.gitrun.com seems interesting. |
I like alternative 3 |
I am afraid alternatives 2,3,5,6,8 will cause shift-reduce conflict. I like alternative 10, which is
similar to Ruby's lambda. |
That might be confusing if you want to assign a lambda to a variable. Alt. 6, 8, and 4 are the least likely to cause conflicts. |
@matz Let's say you decide to go with alternative 10, would you consider also having alternative 7 available? As I see it those should not be mutually exclusive, and I think alternative 7 is proper for quick Streem scripts (c.f. shell scripts) where the number of parameters are few and naming them feels overkill. Just as the meaning My suggestion:
|
From a pure standpoint of appearance, I don't like Ruby's lambda syntax at all. Most modern languages go with something like So big 👎 10, but 👍 5 (6 is also okay). Or, once again, the parser of Streem is supposed to be so complicated and chaotic that you can't implement a standard syntax? |
@shunsukeaida I don't know how other language works (yet), but when the parser see
it's quite difficult for the parser to distinguish |
Alt. 6 is very similar to Alt. 5. Maybe that's what we should go with. |
Anyone here knows Microsoft Powershell (http://technet.microsoft.com/en-us/library/hh847902.aspx - "about_Pipelines")? Streem immediately reminds me of it. In Powershell, objects sent thru the pipeline get assigned to '$_' by default, which would be like option 7, but a single parameter (not sure if you can have more than 1 object sent thru at a time), which is good for quick scripting/oneliners, but when declaring functions you can assign them to named variables (in a more bureaucratic way than most *nixers are probably used to). Anyway, I personally don't fancy the little arrows, typing '()' or '||' requires less finger traveling. So I'd like 7 (by default) plus 3. Also I'd like to note this looks to me like a language/shell for sysadmins, not necessarily full blown programmers. :] |
|
The similarity between the flow operator (
|
) and the block parameter syntax (|x|
) will probably be a source of some confusion since|x|
can be misinterpreted as "a pipe through x".The problem is not the flow operator (
|
). On the contrary – using the pipe as the flow operator conveys the meaning very intuitively for everyone who has ever used a shell, so let's keep that very good choice.Instead I suggest switching from
|x|
to say(x) ->
,(x)
orx ->
to denote block parameters.The
(…) ->
alternative is implemented here: https://github.com/practicalswift/streem/commit/193fa8413d14dce03d609ec597006a40ca678ec1Reasoning:
(parameter1, parameter2, parameter3, …)
should be familiar to most programmers.->
is used for assignment in the Streem syntax (seeop_rasgn
inlex.l
).Summary of discussed alternatives:
Alternative 1 (current syntax).
Alternative 2 (implemented here: https://github.com/practicalswift/streem/commit/193fa8413d14dce03d609ec597006a40ca678ec1).
Alternative 3.
Alternative 4.
The text was updated successfully, but these errors were encountered: