The possible choices for function syntax depends very much on the variable and constant declaration syntax.
If anonymous functions / lambdas are needed, they need to be constructed exactly in a way that grammar ambiguities are avoided, and obviously this depends on the overall grammar.
In the lambda case, many languages also offer shorter forms with types inferred. As lambdas as often used as callbacks or computation functions, this often increases readability for short functions.
An overview of different syntax I often use is this.
There are no clear cut rules, while one would prefer function and lambda follow each other closely, there can be trade-offs with other concerns such as the overall grammar complexity, readability etc.
Some examples:
C++ (note how the capture list with []
also serves to disambiguate the grammar somewhat)
int foo(int a) { ... }
x = [](int a) -> int { ... };
Ruby (syntax is different from function construction, but consistent with other constructs using blocks)
def foo(a) ... end
x = lambda { |a| ... }
Go (function and lambda declarations are very similar)
func foo(a int) int { ... }
x = func(a int) int { ... }
Java (note the special short syntax available for lambdas)
int foo(int a) { ... }
x = a -> { ... }
Swift (similar to Java it has special inferred forms available for lambdas)
func foo(a: Int32) -> Int32 { ... }
y = { a in ... }