Skip to content

Implement lambda shorthand syntax (x -> body)#2

Merged
ochsec merged 1 commit intomainfrom
feature/lambda-shorthand
Mar 1, 2026
Merged

Implement lambda shorthand syntax (x -> body)#2
ochsec merged 1 commit intomainfrom
feature/lambda-shorthand

Conversation

@ochsec
Copy link
Owner

@ochsec ochsec commented Mar 1, 2026

Summary

Adds support for lambda shorthand syntax x -> body as syntactic sugar for Function[{x}, body].

Changes

  • Lexer: Added Arrow token to recognize -> operator, with logic to distinguish from minus operator
  • Parser: Implemented desugaring of arrow syntax into Lambda expressions with single parameter
  • Tests: Comprehensive test suite covering:
    • Lexer token recognition
    • Parser AST generation
    • Equivalence with explicit Function syntax
    • Code generation to Rust closures
    • Integration with Map, Filter, and pipe operations

Example

Map[x -> x * 2, [1, 2, 3]]

Desugars to:

Map[Function[{x}, x * 2], [1, 2, 3]]

Adds `->` arrow operator so `Function[{x}, body]` can be written as
`x -> body`. Desugars to the same Lambda AST node, requiring no
changes to codegen or type inference. Works naturally with pipes:
  data |> Filter[x -> x > 100] |> Map[x -> x * 2]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ochsec ochsec merged commit b1ff15a into main Mar 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant