C++: terser (shorter) lambda == SHORTY (ab-use?)

signa11 | 67 points

Another idea in this vein, but with a surprisingly straightforward implementation (27 lines): https://github.com/GrantMoyer/lambda_hpp

I started out trying to write something like the OP, but changed direction when I convinced myself there would have been no sane way to implement member call syntax. I honestly can't decide if it's cursed or genuinely useful (minus the unicode name, that's cursed).

GrantMoyer | 5 days ago

As if C++ didn't have enough of “black magic” already, there's another layer of that. Just in case you find error messages involving template applications still too readable.

tempodox | 6 days ago

Looks cursed to me.

But TIL dollar sign $ is also valid character for identifiers.

hsfzxjy | 6 days ago
notpushkin | 6 days ago

That's horrifying

porridgeraisin | 6 days ago

I'm sorry I know this is horrific but I still love it. This looks like a better version of Boost Lambda2. I would potentially maybe replace `$` with `_` before using this (which should be easy as a layer) like Boost::Lambda2 but otherwise I'm excited to use it. Not that I would use anything like this in production, but it looks too fun not to play around with.

gnulinux | 5 days ago

huh. very cute. in the past, i had an idea for terser lambda syntax, similar to C#'s expression body functions - which i did end up implementing in clang:

    auto sum = [](auto a, auto b): a+b;
but this is something else. i didn't think i'd like it at first, but actually i think i might be coming around to it. the.. dollar syntax is regrettable, although it's not a show stopper.
foxhill | 6 days ago

Pretty cool. I was wondering what kind of arcane magic they used to get $xxx working, since $ is not a standard identifier char... then I realised they straight up define $arg, $call, etc as constants (makes a lot of sense). And $ really is not an identifier char by the Standard, but evidently some compilers accept it.

mcdeltat | 5 days ago

I fail to see the benefit from the lens of C++23.

pjmlp | 5 days ago

Isn’t this basically the obsolete Boost.Lambda?

pwdisswordfishz | 6 days ago

Not really a new idea. These are expression templates: https://en.wikipedia.org/wiki/Expression_templates

nialv7 | 5 days ago

[dead]

curtisszmania | 5 days ago

[dead]

szundi | 6 days ago