rzimmerman / kal

A powerful, easy-to-use, and easy-to-read programming language for the future.
http://rzimmerman.github.io/kal
MIT License
394 stars 18 forks source link

Javascript on homepage. #73

Closed LarryBattle closed 11 years ago

LarryBattle commented 11 years ago

Your javascript on the homepage is slightly incorrect.

Old Code:

var getUserFriends(userName, next) {
      db.users.findOne({name:userName}, function (err, user) {
          if (err != null) return next(err);
          db.friends.find({userId:user.id}, function (err, friends) {
              if (err != null) return next(err);
              return next(null, friends);
          });
      });
}

New Code:

var getUserFriends = function(userName, next) {
      db.users.findOne({name:userName}, function (err, user) {
          if (err != null) return next(err);
          db.friends.find({userId:user.id}, function (err, friends) {
              if (err != null) return next(err);
              return next(null, friends);
          });
      });
}

Could you update it?

LarryBattle commented 11 years ago

Also, your translation is a bit off. Correct me if I'm wrong.

For this example

    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

Shouldn't

    wait for friendsOfFriend from db.friends.find friend

be

    wait for friendsOfFriend from db.friends.find {userId:friend}

Also, in the example

    var getUserFriends = function (userName, next) {
            db.users.findOne({name:userName}, function (err, user) {
                if (err != null) return next(err);
                getFriendsById(userId, function (err, friends) {
                    if (err != null) return next(err);

Shouldn't

    getFriendsById(userId, function (err, friends) {

be

    getFriendsById(user.id, function (err, friends) {
rzimmerman commented 11 years ago

Thanks so much for catching these bugs. I'll go through and make the fixes soon.

rzimmerman commented 11 years ago

Oops I changed the wrong line. 11e46e3385abd783b3a6d90d8e4c727c917696d1 should fix it.