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

Nested lambdas can't auto-capture free references from the outer scope. #1708

Open
jemc opened this issue Mar 17, 2017 · 4 comments
Open

Nested lambdas can't auto-capture free references from the outer scope. #1708

jemc opened this issue Mar 17, 2017 · 4 comments
Labels
bug Something isn't working needs investigation This needs to be looked into before its "ready for work"

Comments

@jemc
Copy link
Member

jemc commented Mar 17, 2017

As of #1648, the following works:

actor Main
  new create(env: Env) =>
    {() =>
      env.out.print("Hello, world!")
    }()
Building builtin -> /home/jemc/1/code/gitx/ponyc/packages/builtin
Building . -> /home/jemc/1/code/gitx/ponyc/test.jemc
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Optimising
Writing ./test.jemc.o
Linking ./test.jemc
Hello, world!

But the following doesn't:

actor Main
  new create(env: Env) =>
    {() =>
      {() =>
        env.out.print("Hello, world!")
      }()
    }()
Building builtin -> /home/jemc/1/code/gitx/ponyc/packages/builtin
Building . -> /home/jemc/1/code/gitx/ponyc/test.jemc
Error:
/home/jemc/1/code/gitx/ponyc/test.jemc/test.pony:6:9: cannot capture "env", variable not defined
        env.out.print("hello world")
        ^
Error:
/home/jemc/1/code/gitx/ponyc/test.jemc/test.pony:6:9: can't find declaration of 'env'
        env.out.print("hello world")

If lambdas can automatically capture free references from the immediately surrounding scope, I'd expect (principle of least surprise) that they can also do so with free references from an outer scope surrounding that scope, with the surrounding scope being made to capture the reference intermediately.

That is, I'd expect this to happen implicitly:

actor Main
  new create(env: Env) =>
    {()(env) =>
      {()(env) =>
        env.out.print("Hello, world!")
      }()
    }()
@jemc
Copy link
Member Author

jemc commented Mar 22, 2017

Discussed on sync call - @sylvanc agrees it should work, and it's an implementation bug.

@jemc
Copy link
Member Author

jemc commented Jul 17, 2017

Adding the needs discussion tag here so we can check the status of this during the next sync call.

@SeanTAllen
Copy link
Member

I wasn't aware this issue existed.

@SeanTAllen
Copy link
Member

@sylvanc any progress on this?

@SeanTAllen SeanTAllen added needs investigation This needs to be looked into before its "ready for work" bug Something isn't working and removed bug: 1 - needs investigation labels May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigation This needs to be looked into before its "ready for work"
Projects
None yet
Development

No branches or pull requests

3 participants