gkz / LiveScript

LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
http://livescript.net
MIT License
2.32k stars 155 forks source link

Monadic syntax idea (haskell like do statement) #1046

Closed askucher closed 6 years ago

askucher commented 6 years ago

We have


func = (test, cb)->
   return cb "test is not defined" if not test?
   console.log test
   cb null, "ok"

This is very useful case of function, so we need some improved syntax for it

monadic-func = (test)=>
   <0 "test is not defined" if not test?
   console.log test
   <1 "ok"

Both cases should compile the same result.

Please check cb is removed but => is added

monadic-func = (test)=>
   <0 "test is not defined" if not test?
   console.log test
   <1 "ok", 1  # return cb null, "ok", 1
monadic-func = (test)=>
   <0 "test is not defined", 1 if not test? # return cb "test is not defined", 1
   console.log test
   <1 "ok"

P.S. We will implement it anyway, even when you decide to skip this idea. we hate repeat things like cb, return, etc

okhrimenkoalexey commented 6 years ago

good job👍🏼

dmitrii602 commented 6 years ago

Unbelievable!!

Passsword commented 6 years ago

Good point

vendethiel commented 6 years ago

I think a reusable wrapper is more functional and better.

func = (test, cb)->
   return cb "test is not defined" if not test?
   console.log test
   cb null, "ok"

# to
check = (check, fn) -> (...xs, cb) ->
  if check ...xs
    cb that
  else
    cb null wrapper ...xs
func = check do
  (test) -> "test is not defined" unless test?
  (test) -> console.log test

You could also use an exception. Or use &1 to not have to add cb everywhere.

hmaurer commented 6 years ago

Is this a late April Fools'?

askucher commented 6 years ago

@vendethiel there is "ok"?

askucher commented 6 years ago

@hmaurer you ran away and forgot your diapers

hmaurer commented 6 years ago

@askucher let's not be mean on the internet please, we are all civilised people here.

rhendric commented 6 years ago

@askucher, that last comment crosses a line. There hasn't yet been a need for ‘formal’ warnings here but if there were, this would be one.

askucher commented 6 years ago

You can ban me, but I will not tolerate a slyness "Is this a late April Fools" of @hmaurer. it is not a place for such expressions as well

rhendric commented 6 years ago

I'm afraid I disagree. The way I see it, attacking ideas is okay, but attacking people is not.

@hmaurer attacked your idea—he more or less said this proposal is ridiculous. In my opinion, that comment is at least as valid as your friends and coworkers leaving comments that this proposal is amazing. (At least @hmaurer didn't create a GitHub account the same day you created this issue just to leave a comment on it.)

If you found @hmaurer's comment childish, you are free to say that. What I don't want to see is anyone calling anyone a child, as you did. Ideas and comments can and should be attacked—the ones that should remain will have defenders, and the indefensible ones will fall away, and we will all be the better for it. If people are attacked, they will leave the community, and we will all be the poorer for it—and other people passing by may see that this is a community where people get called names for offering their opinions, and never join in, and we all lose again. If you can't tell the difference—if every time you hear ‘your idea is stupid’ it sounds like ‘you are stupid’—then I don't know what to tell you except maybe try to get a thicker skin and a sense of humor about it? But my goal is to keep this community welcoming to everyone, including and especially people who leave critical comments on ideas they think are bad. I want you to be on board with that.

askucher commented 6 years ago

Ok. guys. You are right. The line was crossed. And I'm sorry

But I am going to quit from this community due to developmental lag, which is covered by a thick layer of words instead of deals.

I will continue fund and develop it in a new community. But it will be another language inspired by Livescript but with Type System, Monadic statements and Ethereum like GAS.

You can continue your project like you want to continue it and I will no longer wonder why your language is not popular.