-
Notifications
You must be signed in to change notification settings - Fork 11
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
BREAKING: proper support for closures #8
base: master
Are you sure you want to change the base?
Conversation
The environment must be saved whenever a closure is created, and used when the closure is invoked. Also adds BREAKING keyword which can define anonymous functions.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
It does sound better followed by the Now, anonymous functions aren't exactly “throwaway” — on my example they actually create storage! If a language does not support arrays, objects, or any other kind of compound data structures, you can still get all that if you have closures. I've always found this fascinating... |
You actually don't need anonymous functions. You can define code the same as in Python where functions need to have more than one line, you create a nested named function and return it.
The real problem is that it seems you can define a function without arguments and call a function without arguments. |
Yeah, I noticed that this works, but it's a little cumbersome.
Indeed, there seems to be no syntax for it. |
I was SHOCKED to notice that inner functions do not behave properly (they can't see bindings from the environment where they are defined, since they are all executed in one master environment). This PR resolves that (a bunch of methods that I added to the Environment class are taken from my PL tutorial).
This also adds a
BREAKING
keyword (I didn't have a better idea) that one can use to define anonymous functions. With this additions I wrote the following code, which solves my old little JS quiz.