Placeholder Syntax

The bigest problem with such a feature is scoping. How do you know how big a scope the placeholder is supposed to turn into the closure?

Is foo(bar(_, 5)) translated to foo(|x| bar(x, 5)) (gives us partial application for free! Amazing!) or foo(bar(|x| x, 5))? Or even |x| foo(bar(x, 5))?

In fact, is _.name |x| x.name or (|x| x).name? (More actually illustrative, consider _.call(5), as that method name is actually available on closures.)

You can come up with rules, but they're going to disagree with a large number of people's first guess, no matter which rules you pick.

I personally aesthetically like _ closures, and spent a decent amount of effort trying to describe reasonable rules for how big the closure should be, to avoid surprises. I think it is possible to define clear rules without surprising edge cases and being reasonably useful in all uses, but I also come to the conclusion that it does not fit a language such as Rust which prioritizes locally obvious semantics.

Lack of overloading would generally mean there's only one valid (as in it type checks) interpretation that would compile, but I can't rule out the possibility of an actual semantic ambiguity.

30 Likes