Skip to content
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

Terminating ; missing from next to last function definition #81

Closed
gamecubate opened this issue Oct 25, 2015 · 4 comments
Closed

Terminating ; missing from next to last function definition #81

gamecubate opened this issue Oct 25, 2015 · 4 comments

Comments

@gamecubate
Copy link

A bug?

Compiling this:

(def unless (condition body)
  (if condition
    nil
    body))

(unless true (console.log 'false))

(unless (= 12 (* 2 6))
  (console.log "2*6 != 12!"))

gives that:

var unless = (function(condition, body) {
  return (function() {
    if (condition) {
      return nil;
    } else {
      return body;
    }
  })();
});

(function() {
  if ((!true)) {
    return console.log("false");
  }
})()
(function() {
  if ((!(12 === (2 * 6)))) {
    return console.log("2*6 != 12!");
  }
})()

IOW the next to last function is not terminated with a semi-column, thus triggering an error when the code is executed in the browser;

Uncaught TypeError: (intermediate value)(...) is not a function
@jbr
Copy link
Owner

jbr commented Nov 7, 2015

Thanks for filing this issue, that was a genuine bug.

It's worth noting that you're "reverse shadowing" a macro called "unless." If you want to use the function version instead of the macro version, you'll need to (delete-macro unless) OR rename it, like (rename-macro unless).

I've added #83 to add a warning for situations like this.

As far as the semicolon issue, I just tested this with the significantly improved and rewritten internals. As of 0.3.1, this is the result:

var unless = (function unless$(condition, body) {
  /* unless eval.sibilant:1:0 */

  return (function() {
    if (condition) {
      return nil;
    } else {
      return body;
    }
  })();
});
(function() {
  if ((!true)) {
    return console.log("false");
  }
})();
(function() {
  if ((!(12 === (2 * 6)))) {
    return console.log("2*6 != 12!");
  }
})();

I hope that's what you'd expect. Thanks!

@gamecubate
Copy link
Author

I don't think unless is mentioned in the docs. Correct me if I'm wrong.

@gamecubate gamecubate reopened this Nov 7, 2015
@gamecubate
Copy link
Author

I think it's better for you to decide whether or not to close this, given leaving it opened leaves a reminder of a needed action (documenting unless?). Hence, reopened.

@jbr
Copy link
Owner

jbr commented Nov 7, 2015

@gamecubate You're quite right. The documentation is not thorough and that hampers learning. Thank you for pointing this out. It's a larger issue than unless and sibilantjs.info isn't really intended as documentation as much as it is an intro to the language. I've recently been rewriting the macro system to make it easier to write macros, and as part of that effort I'm going to document all of the macros.

I'm going to close this issue, which was primarily about the semicolon insertion, and have opened #84. Please add any further ideas for docs over there

Thanks again

@jbr jbr closed this as completed Nov 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants