-
-
Notifications
You must be signed in to change notification settings - Fork 663
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
No support for closures in lambdas ? #173
Comments
Hi, this.elements.forEach((sphere: Sphere, index: i32, array: Array<Sphere>): void => {
...
}); And I'm not sure about |
Can't capture yet. Reason is that closures like these usually need GC-support to attach an outer scope to the function being called, so if the inner function changes a value, the outer function sees the change as well. This is especially important for functions being assigned to values that can be called at any time, i.e. when the parent function already finished executing. To work around this for now you could use a global variable that you assign the value to first, read the value from there in the inner function, and maybe set the updated value back in the parent function afterwards. |
@dcodeIO Thanks! |
This makes me think. One optimization we could theoretically do is to compile the |
Thanks for the quick answer guys! |
Hi,
I'm trying to understand AssemblyScript by doing a little project. Is there no closure on lambdas ?
` trace(rayOrigin: Vector3, rayDirection: Vector3, depth: f64): Vector3 {
let tnear: f64 = Infinity;
let sphere: Sphere | null = null;
`
This bit of code doesn't compile, it throws this error.
`ERROR TS2304: Cannot find name 'rayOrigin'.
in assembly/RayTracer.ts(16,1`
Do i need to pass them as parameters to the lambda ?
The text was updated successfully, but these errors were encountered: