[Feature Request] Strict-mode multi-statement lambdas
Nobody has claimed this yet.
- Dominant language
- Mojo
- Stars
- 29.8k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Request
A strict-mode version of lambda that supports multiple statements.
Motivation and Description
Similar to how fn is like a strict-mode version of def, it seems like Mojo might benefit from having a strict-mode version of lambda. It would have the same distinctions as fn does from def, except unlike fn, it would support type inference for arguments and return types where possible.
Furthermore, it would be great if these strict-mode lambdas could support multiple statements. Although Python has been hesitant to add support for multi-statement lambdas in the past, other languages similar to Mojo, such as Swift, Rust, Julia, and Nim, have demonstrated the advantages of supporting them. And given the current prevalence of asynchronous and functional-style programming, this seems like an area where Mojo would benefit from taking inspiration from these other languages.
As for the syntax, maybe the fn keyword could be reused here, but in an anonymous way without specifying a function name. Or maybe the lambda keyword could still be used, but be made strict-mode by default and support multiple statements in a way that is compatible with its current syntax. Or maybe inspiration could be taken from the syntaxes used by Swift closures, Rust closures, or Nim anonymous procs.
There are probably nuances to this feature that I haven't considered yet, so I'd be interested to hear what others think.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or entry points; begin by reviewing the existing lambda and fn language implementation and the linked Swift, Rust, Julia, and Nim syntax references. Done requires an agreed syntax and semantics for strict-mode anonymous lambdas, including multi-statement bodies and type inference, followed by implementation and tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100