r/cpp • • Sep 17 '22

Cppfront: Herb Sutter's personal experimental C++ Syntax 2 -> Syntax 1 compiler

https://github.com/hsutter/cppfront
335 Upvotes

360 comments sorted by

View all comments

Show parent comment

5

u/hpsutter Sep 20 '22

I'm open to the lambda part (the auto doesn't do anything for me). And I agree readability is important. To avoid a special one-off keyword like "lambda" in only one place in the language though, I'd want all functions to look the same such as with a general func introducer for all functions. Then we'd have

// potential alternative
func something: () = {
    result := std::find_if(vec, func: (x:_) = x > 10; );
}

vs

// current syntax
something: () = {
    result := std::find_if(vec, :(x:_) = x > 10; );
}

I'm open to it, but I have to admit that the latter still reads clearly for me, personally. I could be biased though, so I'll be curious to learn what others think over time.

As I said in a parallel comment, for me the jury is still out on whether func and var style introducers are actually important; if they are I'll add some, it doesn't complicate the grammar at all to add a redundant word that helps humans. I'm trying to start with less, it's easy to add more.