proposal: spec: short function literals
**[edit: As of today, end of May 2025, this proposal has received ~1000 comments. Please read the [summary](https://github.com/golang/go/issues/21498#issuecomment-2913318951) before adding more comments. Your ideas may have been discussed already. Thanks.]** **[edit: As of June 4, 2024, a small group of commenters has come to a [narrow conclusion on a workable syntax](https://github.com/golang/go/issues/21498#issuecomment-2941432763). In order to avoid going in circles, please consider the preceding comments before suggesting alternatives. Most likely, they have been discussed already.]** --- Many languages provide a lightweight syntax for specifying anonymous functions, in which the function type is derived from the surrounding context. Consider a slightly contrived example from the Go tour (https://tour.golang.org/moretypes/24): ```go func compute(fn func(float64, float64) float64) float64 { return fn(3, 4) } var _ = compute(func(a, b float64) float64 { return a + b }) ``` Many languages permit eliding the parameter and return types of the anonymous function in this case, since they may be derived from the context. For example: ```scala // Scala compute((x: Double, y: Double) => x + y) compute((x, y) => x + y) // Parameter types elided. compute(_ + _) // Or even shorter. ``` ```rust // Rust compute(|x: f64, y: f64| -> f64 { x + y }) compute(|x, y| { x + y }) // Parameter and return types elided. ``` I propose considering adding such a form to Go 2. I am not propo
Posted by neild on Aug 17, 2017, 6:29 PM
Tags
Related issues
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
github (E-commerce)
proposal: cmd/cgo: cgo without a C toolchain
Replace PowerToys Run with Command Palette
VPS with a vRack leg
Possibility of Portal 1 Code Inclusion
Introducing NewPlayer
Metrics for PRs are never expiring ("memory leak")
ship even more of the compiler in source form
Flatpak Application TRACKING ISSUE
proposal: spec: short function literals
**[edit: As of today, end of May 2025, this proposal has received ~1000 comments. Please read the [summary](https://github.com/golang/go/issues/21498#issuecomment-2913318951) before adding more comments. Your ideas may have been discussed already. Thanks.]** **[edit: As of June 4, 2024, a small group of commenters has come to a [narrow conclusion on a workable syntax](https://github.com/golang/go/issues/21498#issuecomment-2941432763). In order to avoid going in circles, please consider the preceding comments before suggesting alternatives. Most likely, they have been discussed already.]** --- Many languages provide a lightweight syntax for specifying anonymous functions, in which the function type is derived from the surrounding context. Consider a slightly contrived example from the Go tour (https://tour.golang.org/moretypes/24): ```go func compute(fn func(float64, float64) float64) float64 { return fn(3, 4) } var _ = compute(func(a, b float64) float64 { return a + b }) ``` Many languages permit eliding the parameter and return types of the anonymous function in this case, since they may be derived from the context. For example: ```scala // Scala compute((x: Double, y: Double) => x + y) compute((x, y) => x + y) // Parameter types elided. compute(_ + _) // Or even shorter. ``` ```rust // Rust compute(|x: f64, y: f64| -> f64 { x + y }) compute(|x, y| { x + y }) // Parameter and return types elided. ``` I propose considering adding such a form to Go 2. I am not propo
Comments (0)
No comments yet. Start the discussion.