Re:Pascal at Apple
by WalterBright on Saturday July 22, 2017 @05:40PM
(#14829546)
A lot of the goto's were used to use a common sequence of code followed by a return. With nested functions, the nested function contains the common sequence of code, and you just:
instead of:
[ Parent
| on HN ]
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?
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.