Higher order function stage tests closures

In #EY3, the “Higher order function” stage all of the tests involve capturing the environment in a function.

See this test for instance:

fun makeGreeter(greeting) {
  fun greet(name) {
    print greeting + " " + name;
  }
  return greet;
}

var sayHello = makeGreeter("Hello");
sayHello("Bob");

The “greet” function uses the “greeting” variable which is not in the global scope. The tests are valid, they just happen to be testing behavior that ought to belong in “Closures” #GG6.

This isn’t a big deal, but it’s just kind of a pain to have to run tests twice for the same behavior. Maybe they should be merged into one stage or the Higher Order Function stage should simply return functions from a function without capturing the parent function’s arguments?

Relevant links (I don’t know if these are useful, this is my first time posting here):
Higher order functions #ey3
Closures #gg6

Like I said above, this is my first post in these forums, please let me know if I should have posted elsewhere or included something different in my post :face_with_diagonal_mouth:

1 Like

Thanks for highlighting this! cc-ing @ryan-gang, who worked on this extension and should have more context

We’ve fixed the issue in this PR.

@ellnix thanks again for highlighting the issue!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.