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

Capturing variables in F# loop #551

Closed
Jand42 opened this issue Jun 1, 2016 · 1 comment
Closed

Capturing variables in F# loop #551

Jand42 opened this issue Jun 1, 2016 · 1 comment

Comments

@Jand42
Copy link
Member

Jand42 commented Jun 1, 2016

The for i = ... currently checks if the index variable's value is captured, but capturing another variable in a block does not get correctly scoped. Example:

let arr = [| 1 .. 10 |]
let funcs = ResizeArray()
let res = ResizeArray()
do
for i in [| 0 .. 9 |] do
    let j = arr.[i]
    funcs.Add(fun () -> res.Add j)
for f in funcs do
    f()

Running the JavaScript translation, the result of res is currently repeating 10, because a single j variable is captured in the created functions, which is not correct semantics for F#.

@Jand42
Copy link
Member Author

Jand42 commented Jan 9, 2018

@Jand42 Jand42 closed this as completed Jan 9, 2018
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

1 participant