News for hackers. Stuff that matters.
Re:Kal – a clean JavaScript alternative without callbacks by rybosome on Friday August 16, 2013 @09:28PM (#6227820)
It's remarkable how similar this code looks to the monadic way of doing it.

For this Kal code...

    task getUserFriends(userName)
      wait for user from db.users.findOne {name:userName}
      wait for friends from db.friends.find {userId:user.id}
      if user.type is 'power user'
        for parallel friend in friends
          wait for friendsOfFriend from db.friends.find friend
          for newFriend in friendsOfFriend
            friends.push newFriend unless newFriend in friends
      return friends
Here's a pseudo-ish implementation in pseudo-ish Haskell.

  getUserFriends userName = do
    user <- findUser userName
    friends <- findFriends user
    if (User.type user) == "power user"
      then friends ++ parMap rdeepseq $ (getSecondNodes friends) friends
      else friends
		
  getSecondNodes firstNodes friend = do
    secondNodes <- findFriends friend
    diff firstNodes secondNodes


I like the concept of Kal, and I look forward to seeing what people do with it. Regarding syntax, I have to admit that I share the opinions of a few others in terms of preferring symbols over so many keywords, but that's a minor nitpick. Great job!
Re:Kal – a clean JavaScript alternative without callbacks by rzimmerman on Friday August 16, 2013 @10:18PM (#6227935)
Thanks! I had not thought to make the comparison to Haskell and monads. That's pretty interesting.

A lot of people prefer symbols over keywords, and I think that's mainly a readability issue. I personally prefer more keywords with good syntax highlighting, so that's what I went with (and why I almost immediately made a .tmbundle).

Re:Kal – a clean JavaScript alternative without callbacks by iandanforth on Saturday August 17, 2013 @01:41PM (#6229732)
Coming from a Python background I appreciate the verbosity. There are times when symbols and being concise may be necessary, but I find a non-expert human readable default to be very appealing.

Thanks for your hard work!

Re:Kal – a clean JavaScript alternative without callbacks by GeZe on Friday August 16, 2013 @10:29PM (#6227958)
If you are looking for a syntax closer to Haskell's, you can take a look at LiveScript (http://livescript.net/)

eg.

    getUserFriends = (userName) ->
      user <- findUser userName
      friends <- findFriends user
      ...
Specifically, the section on "backcalls": http://livescript.net/#backcalls
Re:Kal – a clean JavaScript alternative without callbacks by damncabbage on Saturday August 17, 2013 @08:49AM (#6228954)
If you are looking for Haskell, you can take a look at Fay (https://github.com/faylang/fay/wiki).
Re:Kal – a clean JavaScript alternative without callbacks by chx on Saturday August 17, 2013 @09:57AM (#6229087)
Re:Kal – a clean JavaScript alternative without callbacks by seanmcdirmid on Saturday August 17, 2013 @03:54AM (#6228496)
Back calls look like array programming gone even crazier. Was live script inspired by APL?
Re:Kal – a clean JavaScript alternative without callbacks by pcj on Friday August 16, 2013 @10:19PM (#6227940)
This is beautiful work! I see small shades of inspiration from the .Net TPL[1] and the more recent async-await paradigm[2] in C#. But, this is way more concise and beautiful implementation :-)

[1] - http://msdn.microsoft.com/en-us/library/vstudio/system.threa...

[2] - http://msdn.microsoft.com/en-us/library/vstudio/hh191443.asp... and http://msdn.microsoft.com/en-us/library/vstudio/hh156528.asp...

Re:Kal – a clean JavaScript alternative without callbacks by rzimmerman on Friday August 16, 2013 @10:57PM (#6228012)
Thanks! I was wondering if someone would make that comparison. I saw async-await a little after I started working on this and felt it was good confirmation that this was actually a reasonable idea.
Re:Kal – a clean JavaScript alternative without callbacks by eru on Tuesday August 20, 2013 @03:27PM (#6245982)
And, of course, the Haskell do-notation gets de-sugared into tons of call-backs by the compiler.