Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: Kaz Kylheku Newsgroups: comp.compilers Subject: Re: Is multi-level function return possible? Date: Tue, 11 Mar 2014 22:15:36 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 51 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-03-025@comp.compilers> References: <14-03-020@comp.compilers> <14-03-022@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: miucha.iecc.com 1394679944 33955 64.57.183.58 (13 Mar 2014 03:05:44 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Thu, 13 Mar 2014 03:05:44 +0000 (UTC) Keywords: code, Pascal Posted-Date: 12 Mar 2014 23:05:43 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:1147 On 2014-03-11, Anton Ertl wrote: > noitalmost writes: >>Is this a doable thing for a Pascal-like language that is meant to be >>compiled? I have a multi-level break which works within a procedure, but the >>return across procedure boundaries seems to add a lot of complications. > > Yes, in Pascal you can goto a label that is in a containing procedure > or function, even across several levels. That is a very rarely used I.e. you can jump out of a "downward funarg" closure in that original Pascal, back to the parent environment, just like in Lisp. > feature of the language, and Wirth removed it (along with goto) from > his later languages. Then Cardelli added lexically scoped symbol macros to Modula-3, not unlike (symbol-macrolet ...) in the form of the new, improved version of the WITH statement. Maybe one day these Pascalites will assemble a complete language that has everything at the same time. > The more common feature is to have exceptions that you can throw and > that can be caught in a function/procedure/method several levels > further out. > > 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. I.e. it's not really purely lexical. Resolving the label identifier is lexical, but the situation is dynamic. 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 jsut 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.)