Live data from Hacker News

Kal – a clean JavaScript alternative without callbacks

rzimmerman.github.io

81–90 of 130 posts

Re: Kal – a clean JavaScript alternative without callbacks

#81

So instead of encouraging you to actually fix the bad nested callback code, you can dress it over with fancy syntax. Well done on making a whole language though. It's pretty challenging and I hope you do well. Aside: This seems very similar to narrativeJS in concept http://www.neilmix.com/narrativejs/doc/

What do you mean by "actually fix?"

Re: Kal – a clean JavaScript alternative without callbacks

#83
Beautiful work. The `for parallel` notation is a really interesting way of writing it.

It seems like a number of folks in this thread have expressed interest in your process -- both of designing the feature set, and of gradually bootstrapping it away from CoffeeScript to become self-hosting. I'd love to hear more, if not here, then in a blog post, perhaps...

Re: Kal – a clean JavaScript alternative without callbacks

#85
How many times do I have to say this. Generator/Yields and equivalent constructs don't actually solve the callback problem, they exacerbate it. That is, because you only get to direct one call-level down, but, that's now how you'd code. You'd have some perfectly synchronous code until it hits some infrastructure I/O part some N call layers down, and then now what? You're gonna convert everything to yields? Got any idea how messy that is?

Javascript needs proper co-routines. Nothing short of co-routines will solve the issue. Please lookup microthreads, greenlets, fibres, etc.

Re: Kal – a clean JavaScript alternative without callbacks

#86
post #85

How many times do I have to say this. Generator/Yields and equivalent constructs don't actually solve the callback problem, they exacerbate it. That is, because you only get to direct one call-level down, but, that's now how you'd code. You'd have some perfectly synchronous code until it hits some infrastructure I/O part some N call layers down, and then now what? You're gonna convert everything to yields? Got any id…

I think you have it wrong, generators would solve the problem. If you have asynchronous code N call layers down, then everything above it would be asynchronous as well. So you would only need to yield the first call.

Check how Q.nfcall works.

Re: Kal – a clean JavaScript alternative without callbacks

#87
post #85

How many times do I have to say this. Generator/Yields and equivalent constructs don't actually solve the callback problem, they exacerbate it. That is, because you only get to direct one call-level down, but, that's now how you'd code. You'd have some perfectly synchronous code until it hits some infrastructure I/O part some N call layers down, and then now what? You're gonna convert everything to yields? Got any id…

exacerbate is the correct spelling

Re: Kal – a clean JavaScript alternative without callbacks

#88
post #61

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…

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 Specifically, the section on "backcalls": http://livescript.net/#backcalls

Back calls look like array programming gone even crazier. Was live script inspired by APL?

Re: Kal – a clean JavaScript alternative without callbacks

#89
post #86
post #85

How many times do I have to say this. Generator/Yields and equivalent constructs don't actually solve the callback problem, they exacerbate it. That is, because you only get to direct one call-level down, but, that's now how you'd code. You'd have some perfectly synchronous code until it hits some infrastructure I/O part some N call layers down, and then now what? You're gonna convert everything to yields? Got any id…

I think you have it wrong, generators would solve the problem. If you have asynchronous code N call layers down, then everything above it would be asynchronous as well. So you would only need to yield the first call. Check how Q.nfcall works.

That's a faulty assertion. A generators working principle is that it can resume into the closure if the "caller" is looping over the generator.

Let's assume a simple call stack, A -> B -> C. Now C would be a generator, so B has to loop over C instead of just calling C.

But what about A? Well if B is now looping, and if yielding out of a loop is how you cooperatively multitask, then A now has to loop over B. So you have to convert the entire call stack from A -> B -> C to A(for ... in B(for ... in C)).

You can argue that a compiler can make this invisible, however there are some serious drawbacks with that in that:

1) One solution would be to convert any call into a loop. How do you know which ones are actual calls (stuff like Math.pow etc?) 2) You only convert things that have generators in their call stack to loops, but how do you know that?

Both the above scenarios would depend on being able to infer the "generatoricity" of the called symbol. Something which is very, very hard to do for dynamic languages like Javascript.

Co-routines work differently. Co-routines save the entire call stack and restore another one on switching to somewhere different. Hence if you have A -> B -> C and C is some I/O that would have to go to some scheduler, then the A -> B -> C call stack is saved, the co-routine would switch to say, Main -> Scheduler, the scheduler would do its work, and when it's ready, it switches back to A -> B -> C where that co-routine left of.

Re: Kal – a clean JavaScript alternative without callbacks

#90
post #7

The title is kinda funny to the russian ear because kal means feces in Russian :)

That is really unfortunate... I chose it because it in Hebrew it roughly means something like easy/simple/BASIC. edit: More importantly, does that make you more or less likely to use it?

It's kinda fun and doesn't affect chances that I'll be using it, but I'd imagine it would be funny when someone will try to convince boss to use Kal :)
Post reply on HN