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

Comments

Projects
None yet
2 participants
@polybuildr
Copy link
Owner

commented May 11, 2017

Hoist functions based on later definitions.

f();
fn f() {}

should work.

@bollu

This comment has been minimized.

Copy link
Contributor

commented May 16, 2017

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

@polybuildr

This comment has been minimized.

Copy link
Owner Author

commented May 16, 2017

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

This comment has been minimized.

Copy link
Owner Author

commented Jun 11, 2017

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

This comment has been minimized.

Copy link
Owner Author

commented Jun 11, 2017

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

@polybuildr polybuildr closed this Jun 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.