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

First class functions / lambdas #8351

Open
mppf opened this issue Feb 1, 2018 · 5 comments
Open

First class functions / lambdas #8351

mppf opened this issue Feb 1, 2018 · 5 comments

Comments

@mppf
Copy link
Member

mppf commented Feb 1, 2018

This issue tracks problems with first class functions.

Design needed

The language design for first-class functions is not complete. It's unclear if capturing variables is legal, and if so, how they are captured. See also #11506.

Workaround

First-class functions are currently translated by the compiler into classes with this methods. An alternative (that has better support) is to declare a "function object" like so:

proc main(){
  var x = 10;

  record Lambda {
    proc this(z:int) {
      return z*x;
    }
  }
  var foo = new Lambda();

  writeln(foo(3));

}

Relevant issues

Design Precedents

It might be interesting to investigate function arguments in Swift and C++11 lambdas as design points.

@ben-albrecht
Copy link
Member

Using this issue as a place to track shortcomings of today's FCFs (without opening new issues), as kind of a PSA for anyone searching for FCF issues:

  • Today's FCF implementation relies on virtual dispatch, which makes them unsuitable for any performance-critical codes.

@mppf
Copy link
Member Author

mppf commented Feb 22, 2019

It might be better for a series of begin-on statements as might come up in chained futures for the first class functions to be allocated on the heap. An interesting case to think about is getting the length of a distributed linked list with chained futures. We don't want the originating stacks to have to remain around for some reason.

@mppf
Copy link
Member Author

mppf commented Jun 6, 2019

The current implementation doesn't have a way to reason about the type of a throwing first-class-function.

@LouisJenkinsCS
Copy link
Member

Should there be individual issues to discuss specific parts of First Class Functions design?

@mppf
Copy link
Member Author

mppf commented Jun 6, 2019

Yes, and there are, e.g. #11506 and #9871.

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

3 participants