Plan for HS4
Lambdas[edit]
Lambdas are like subscript, but are usable as an expression, omit the script name, and the body is implicitly 'return' instead of 'do'. References to subscripts (@subscriptname) will also be allowed, and are different syntax for the same thing. We could possibly also allow a subscript block to be used as an expression. Both subscripts and lambdas form closures. Lambda expressions and references to subscripts evaluate to function/callable objects.
I don't like 'lambda', makes no sense to anyone not familiar with lambda calculus and is even hard to type.
So here are some possibilities for the syntax, with comments (comments follow the proposal).
Just omitting the subscript/function name but otherwise identical, e.g.
- func, x, y, (x.type == LATENT)
is highly ambiguous as an expression and ugly because of the commas, e.g.:
- filter(list, func, x, y, (x.type == LATENT))
so would require surrounding brackets:
- filter(list, (func, x, y, (x.type == LATENT)))
I don't like the double brackets, but highly consistent with subscript
- filter(list, func(x, y)(x.type == LATENT))
Looks like a function call...
- filter(list, func(x, y, x.type == LATENT))
Here func acts like a lazy function taking an expression as last arg. Looks too much like a normal call
- filter(list, func(x, y) x.type == LATENT)
Looks clean, can optinally put brackets around body (enforce it if contains commas)
- filter(list, func{x, y}(x.type == LATENT))
Hard to see {,}'s, completely inconsistent with dict literals
- filter(list, <Func>(x, y, x.type == LATENT))
Meant to be sort of consistent with type decls, but doesn't allow commas in body
- filter(list, <Func(x,y)> x.type == LATENT)
- filter(list, <Func, x, y>(x.type == LATENT))
Inconsistent use of type brackets
- filter(list, Func<x, y>(x.type == LATENT))
Inconsistent use of type brackets, but quite similar to other languages
- filter(list, <Func>(x, y, (x.type == LATENT)))
Rather verbose
- filter(list, func(x, y): x.type == LATENT)
Bad use of :
- filter(list, (x, y -> x.type == LATENT))
- filter(list, (x, y) -> x.type == LATENT)
Using pure syntax instead of words goes against HS norms
- filter(list, func(x, y)-> x.type == LATENT)
- filter(list, (func, x, y -> x.type == LATENT))
- filter(list, func(x, y -> x.type == LATENT))
Since nearly all other suggestions are anyway, these use totally new syntax.