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

Closures #73

Closed
kengorab opened this issue Sep 17, 2019 · 1 comment
Closed

Closures #73

kengorab opened this issue Sep 17, 2019 · 1 comment

Comments

@kengorab
Copy link
Owner

kengorab commented Sep 17, 2019

Functions are first-class citizens, and should be assignable to bindings inline. These functions, which can be thought of as lambdas, can have bodies which "close over" variables.

Syntax

func getCounter() {
  var count = 0
  val inc = () => count = count + 1
  val printCount = () => println("Count: " + count)

  { 
    inc: inc, 
    printCount: printCount
  }
}

val counter = getCounter()
counter.printCount()  // Prints "Count: 0"
counter.inc()
counter.printCount() // Prints "Count: 1"
@kengorab kengorab created this issue from a note in Language Core (To Do) Sep 17, 2019
@kengorab kengorab mentioned this issue Sep 17, 2019
@kengorab
Copy link
Owner Author

kengorab commented Apr 3, 2020

While the syntax for lambdas has not yet been implemented, the functionality for closures to close over locals has been successfully implemented over the course of #83, #85, #86, #87, #88, and #95.

@kengorab kengorab closed this as completed Apr 3, 2020
@kengorab kengorab moved this from To Do to Done in Language Core Apr 3, 2020
@kengorab kengorab moved this from Done to New Done in Language Core May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant