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

Hoist functions #27

Closed
polybuildr opened this issue May 11, 2017 · 4 comments
Closed

Hoist functions #27

polybuildr opened this issue May 11, 2017 · 4 comments

Comments

@polybuildr
Copy link
Owner

Hoist functions based on later definitions.

f();
fn f() {}

should work.

@bollu
Copy link
Contributor

bollu commented May 16, 2017

I'm not sure I understand: what happens with mutual recursion?

@polybuildr
Copy link
Owner Author

I'm not sure I understand: what happens with mutual recursion?

Mutual recursion works. :P The idea is that both functions need to be defined before the first call. So,

fn foo() { bar(); }
fn bar() { foo(); }
foo();

works fine because the first call is made after both functions are defined. And since the body is evaluated only after both functions are in the environment, there are no problems.

@polybuildr
Copy link
Owner Author

Looking at a piece of Javascript today:

f();
var f = 5;
// f();
function f() {
    console.log("Hello");
}
f();

The last line causes an error. This leads to a lack of locality of effects, which suggests that this might not be a good idea. If you wish you declare intent first, and then give the function bodies, you could easily move them to another file and import (when importing support actually arrives).

@polybuildr
Copy link
Owner Author

Rejecting the idea. Can be better solved by imports when the time comes. (Some rationale at https://blog.vghaisas.com/hoisting-and-locality/).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants