Re: Is multi-level function return possible?

anton@mips.complang.tuwien.ac.at (Anton Ertl)
Thu, 13 Mar 2014 17:05:46 GMT

          From comp.compilers

Related articles
Is multi-level function return possible? noitalmost@cox.net (noitalmost) (2014-03-10)
Re: Is multi-level function return possible? kaz@kylheku.com (Kaz Kylheku) (2014-03-11)
Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (2014-03-11)
Re: Is multi-level function return possible? gneuner2@comcast.net (George Neuner) (2014-03-11)
Re: Is multi-level function return possible? lkrupp@pssw.com (Louis Krupp) (2014-03-11)
Re: Is multi-level function return possible? kaz@kylheku.com (Kaz Kylheku) (2014-03-11)
Re: Is multi-level function return possible? tkowaltowski@gmail.com (Tomasz Kowaltowski) (2014-03-12)
Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (2014-03-13)
Re: Is multi-level function return possible? yaldnif.w@blueyonder.co.uk (Bill Findlay) (2014-03-14)
Re: Is multi-level function return possible? ivan@ootbcomp.com (Ivan Godard) (2014-03-13)
Re: Is multi-level function return possible? gneuner2@comcast.net (George Neuner) (2014-03-14)
Re: Is multi-level function return possible? gneuner2@comcast.net (George Neuner) (2014-03-14)
Re: Is multi-level function return possible? marcov@toad.stack.nl (Marco van de Voort) (2014-03-14)
Re: Is multi-level function return possible? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2014-03-14)
[23 later articles]
| List of all articles for this month |

From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.compilers
Date: Thu, 13 Mar 2014 17:05:46 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
References: 14-03-020 14-03-022 14-03-025
Keywords: code, Pascal
Posted-Date: 13 Mar 2014 21:00:30 EDT

Kaz Kylheku <kaz@kylheku.com> writes:
>On 2014-03-11, Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>> noitalmost <noitalmost@cox.net> 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]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.