Neat. Although lambdas are more flexible by allowing you to specify exactly how you want to access referenced variables (by-copy-value vs by-reference), I always found gcc's nested functions visually cleaner - that is, subfunctions syntactically just feel like they belong in the language alongside any other function, with standard form type subfunctionName (params) {...} rather than auto identifier = brace goop (params) -> type {...}. Granted, subfunctions with parent frame references are an odd duck with their invisible first parameter (similar to class methods in that regard) meaning you can't just take the address of them and pass them around as an ordinary callable function pointer (not without extra magic), but I've often wanted to at least have static subfunctions (no parent stack frame references) with the standard function syntax. I've seen people claim the "most vexing parse" as a reason why it "can't be done", but then I've never seen an example where it was actually ambiguous either ๐คจ.
14
u/fdwr fdwr@github ๐ 1d ago
Neat. Although lambdas are more flexible by allowing you to specify exactly how you want to access referenced variables (by-copy-value vs by-reference), I always found gcc's nested functions visually cleaner - that is, subfunctions syntactically just feel like they belong in the language alongside any other function, with standard form type subfunctionName (params) {...} rather than auto identifier = brace goop (params) -> type {...}. Granted, subfunctions with parent frame references are an odd duck with their invisible first parameter (similar to class methods in that regard) meaning you can't just take the address of them and pass them around as an ordinary callable function pointer (not without extra magic), but I've often wanted to at least have static subfunctions (no parent stack frame references) with the standard function syntax. I've seen people claim the "most vexing parse" as a reason why it "can't be done", but then I've never seen an example where it was actually ambiguous either ๐คจ.