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

@polybuildr polybuildr commented May 11, 2017

Hoist functions based on later definitions.

f();
fn f() {}

should work.

@bollu
Copy link
Contributor

@bollu bollu commented May 16, 2017

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

Loading

@polybuildr
Copy link
Owner Author

@polybuildr polybuildr 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.

Loading

@polybuildr
Copy link
Owner Author

@polybuildr polybuildr 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).

Loading

@polybuildr
Copy link
Owner Author

@polybuildr polybuildr 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/).

Loading

@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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants