Re:Pascal at Apple
by vram22 on Saturday July 22, 2017 @06:09PM
(#14829699)
Got it now, thanks. But, this (the "return common();") could be done even if the function "common" was not nested within the current function, but defined outside of it, right? So what is the benefit of defining "common" as a nested function? Is it because it then has access to, and can use, variables defined in the outer function?
[ Parent
| on HN ]
Re:Pascal at Apple
by WalterBright on Sunday July 23, 2017 @12:58AM
(#14830974)
Yes, you can do it that way. But then you'll need a "context pointer" to pass references to the locals it'll need, and the function will need to be located "someplace else", meaning it is not encapsulated.
I've done that for years with C and C++. Nested functions are so much nicer and clearer.