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: Sun, 16 Mar 2014 17:19:06 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 39 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-03-044@comp.compilers> References: <14-03-020@comp.compilers> <14-03-022@comp.compilers> <14-03-025@comp.compilers> <14-03-030@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: miucha.iecc.com 1394993088 34125 2001:470:1f07:1126:0:676f:7373:6970 (16 Mar 2014 18:04:48 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sun, 16 Mar 2014 18:04:48 +0000 (UTC) Keywords: code, design, Pascal Posted-Date: 16 Mar 2014 14:04:48 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:1166 George Neuner writes: >YMMV, but ISTM that recursion is not really relevant to the issue: >lexical scoping by itself introduces the potential for name shadowing >and the rule always has been to reference the instance which is >defined "closest" to the point of use. The addition of recursion >simply makes locating that closest instance - at least in part - a >runtime operation rather than a compile time operation. Take a look at the example from Bakul Shah in http://compilers.iecc.com/comparch/article/14-03-042. There the "goto lab1" skips one invocation of top to jump into a top frame that is further out. There is no more run-time operation necessary than without recursion: the goto just follows the static link chain for as many levels as are lexically between the goto and the target label (in this case one), that's all. >Standard Pascal did have not have closures: you could pass a function >by name as an argument to another, but its definition had to be >visible both at the point of passing the name and at the point of >invocation [through the aliasing argument]. Not sure what you mean with "the aliasing argument", but the original name need not be visible at the point of invocation. Pascal's function/procedure arguments have many properties of full closures, in particular access to variables of enclosing scopes, but unlike first-class closures, you could not store them into variables or pass them out from functions. Language design note: Given that nested functions have fallen out of favour in the Algol-family world (in C and its offspring), I wonder if they only really gain usefulness when combined with first-class closures. - anton -- M. Anton Ertl anton@mips.complang.tuwien.ac.at http://www.complang.tuwien.ac.at/anton/