Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!news.misty.com!news.iecc.com!.POSTED!nerds-end From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.compilers Subject: Re: Is multi-level function return possible? Date: Thu, 13 Mar 2014 17:05:46 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 50 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-03-027@comp.compilers> References: <14-03-020@comp.compilers> <14-03-022@comp.compilers> <14-03-025@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: miucha.iecc.com 1394758830 67213 2001:470:1f07:1126:0:676f:7373:6970 (14 Mar 2014 01:00:30 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Fri, 14 Mar 2014 01:00:30 +0000 (UTC) Keywords: code, Pascal Posted-Date: 13 Mar 2014 21:00:30 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1149 Kaz Kylheku writes: >On 2014-03-11, Anton Ertl wrote: >> noitalmost writes: >> The difference between these languages features is that Pascal's goto >> is statically scoped, whereas exceptions are dynamically scoped. > >But if Pascal had upward funargs (closures that can be returned from the scope >in which they are created), then the goto, though lexically scoped, would have >have a test to detect that its target is no longer in the dynamic scope. Pascal does not have full closures. You can pass a function/procedure as a parameter (which allows cool things), but that's all; no general function/procedure variables, no and no returning of functions/procedures or otherwise treating them as values. >Also, never mind full closures: consider the situation that the function is >simply recursive. > >Recursion means there is possibly more than one activation of the environment >which contains the target label of the goto. Which activation is chosen as the >jump target? Does the goto return to the same recursion level in which >the closure was created or does it just find the innermost activation of >that label? > >If the closure just goes to the innermost block which has the label, >then the target resolution is in fact dynamically scoped, even though >the label is lexical. (Because the target block is not lexically captured >along with the closure, but chosen just from whatever is visible at the >time the goto takes place.) From what I remember it's truly lexically scoped (and the mechanism to implement it is the same as for local variables), but if you want to make sure, you can read the spec. But thinking about it makes me wonder: Can you come up with an example that shows the difference? And can you come up with a useful example where there is a difference? - anton -- M. Anton Ertl anton@mips.complang.tuwien.ac.at http://www.complang.tuwien.ac.at/anton/ [Yes, it's lexically scoped. Pascal functions use displays, which keep the frame pointers of all of the lexically enclosing blocks with variables visible in a routine, which are filled in by chasing pointers to the calling function's display. So in case of recursion, the display has the most recent frame pointer. You can't get much more complicated than this and still use a single stack. -John]