google / google/jsonnet

Lightweight lambda syntax

Open
#129 13 comments 4 reactions 0 assignees View on GitHub
enhancement
Dominant language
Jsonnet
Stars
7.6k
Forks
475
PR merge metrics
No merged PRs in 30d

Description

One of jsonnet's big selling points is being able to write functions and pass them around as values. Can we have a more lightweight syntax for anonymous functions than the `function (args) ...` one? I catch myself deliberately trying to to avoid writing them due to the syntactic noise.

I don't really have a proposal for the syntax I want, but here are a few lightweight ones (not sure how compatible they are with your current grammar):
- Scala: `(arg1, arg2) => body` (probably requires nontrivial lookahead and complicates the parser, but is pretty appealing from a human standpoint)
- Haskell: `\arg1 arg2 -> body` (all functions are unary, but this is a shorthand for two lambdas)
- Nix: `arg: body` (all functions are unary)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.