Inline functions / closures / lambdas
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
Especially with generics ( https://github.com/ethereum/solidity/issues/869 ) it might get more important to allow the definition of functions inline. There has also been a proposal to have `require()` take a custom error, and due to the evaluation rules, it might be an option to take a function that returns an error as the second parameter.
Both use-cases demand a shorthand notation to define inline functions like we have in python or rust.
Proposal:
The expression `(Param...) => Expression` evaluations to an internal function type that returns the value of the expression. The return type of the function is the type of the expression.
This can be shortened to `=> Expression` if the parameters are empty.
If we want to allow full code blocks like in `(Param...) => { ... }`, we need explicit return statements and probably also return variables to be specified explicitly.
Capturing of local variables is a whole other problem.
Contributor guide
Research direction
Start by reading this proposal and the related issue #869. Define and agree on the syntax and semantics for expression lambdas, including return behavior, full code blocks, and local-variable captures; the work is done only when those design questions have an accepted specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- blockchain, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100