Path: csiph.com!goblin2!goblin3!goblin.stu.neva.ru!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: bartc Newsgroups: comp.compilers Subject: Re: Add nested-function support in a language the based on a stack-machine Date: Tue, 6 Mar 2018 19:02:27 +0000 Organization: Compilers Central Lines: 51 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <18-03-030@comp.compilers> References: <18-02-009@comp.compilers> <18-02-012@comp.compilers> <18-02-016@comp.compilers> <18-02-018@comp.compilers> <18-02-023@comp.compilers> <18-02-029@comp.compilers> <18-02-032@comp.compilers> <18-02-034@comp.compilers> <18-03-002@comp.compilers> <18-03-012@comp.compilers> <18-03-020@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="79889"; mail-complaints-to="abuse@iecc.com" Keywords: code, comment Posted-Date: 07 Mar 2018 12:44:33 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Content-Language: en-GB Xref: csiph.com comp.compilers:1981 On 05/03/2018 19:39, George Neuner wrote: > On Fri, 02 Mar 2018 09:30:42 GMT, anton@mips.complang.tuwien.ac.at > (Anton Ertl) wrote: >> Wrong. Consider the following nesting of functions: >> >> A >> B >> C >> D >> >> With a display, in C you have built up a display pointing to the >> frames of C, B, and A. When performing a call from C to D, you throw >> that away and replace it with a display pointing to just the frame of >> D. When returning from D, you have to restore the old display. > > No. D and A are at the same lexical level. On entry, D will replace > A's entry in the display, and will restore A's entry on exit. > > The scope rules say D can't see or call B or C. What scope rules? As I don't think this is for a specific language. Even in C, some versions of which have nested functions, it is possible to set up a function pointer to C(), which can later be called from D() without first calling A(). And in my own language, it is possible for code in D() to directly call A.B.C() without entering A. Although in this one, C() can't access any stack-allocated data of B or A; partly for this reason (data may not be undefined if called from outside), and also because it would be fiddly to do anyway, even if called from B() and A(), as the thread demonstrates. (C() can access static data of A() and B(), also types, named constants, enums, and other local functions, so it can still be worthwhile having local functions with such a restriction.) -- bartc [The discussion so far has mostly been about Algol/Pascal style languages where you can't peek into blocks and contexts go away when a routine returns so there are no closures. I agree that if you relax those rules, life gets more complicated. Hypothetical question: Algol60 call by name was a mistake. They intended an elegant definition of call by reference and didn't realize until Jensen's device what they'd done. If they'd done what they intended and we didn't have to invent thunks, how would programming languages be different? -John]