Skip to content

Inline functions / closures / lambdas #12297

Open
@chriseth

Description

@chriseth

Especially with generics ( #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    high effortA lot to implement but still doable by a single person. The task is large or difficult.high impactChanges are very prominent and affect users or the project in a major way.language design :rage4:Any changes to the language, e.g. new featuresmust have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.needs designThe proposal is too vague to be implemented right away

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions