Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1157

Re: Is multi-level function return possible?

Path csiph.com!usenet.pasdenom.info!news.lightlink.com!news.iecc.com!.POSTED!nerds-end
From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.compilers
Subject Re: Is multi-level function return possible?
Date Fri, 14 Mar 2014 21:34:19 +0000 (UTC)
Organization Aioe.org NNTP Server
Lines 123
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <14-03-035@comp.compilers> (permalink)
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 1394834437 76259 2001:470:1f07:1126:0:676f:7373:6970 (14 Mar 2014 22:00:37 GMT)
X-Complaints-To abuse@iecc.com
NNTP-Posting-Date Fri, 14 Mar 2014 22:00:37 +0000 (UTC)
Keywords Pascal, code
Posted-Date 14 Mar 2014 18:00:37 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:1157

Show key headers only | View raw


On 2014-03-14, George Neuner <gneuner2@comcast.net> wrote:
> On Tue, 11 Mar 2014 22:15:36 +0000 (UTC), Kaz Kylheku
><kaz@kylheku.com> wrote:
>
>>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?
>
> 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.

But we have the option that we don't want the closest instance, since
this isn't lexical scope.

E.g. restarts in Common Lisp. compute-restarts can return all the
restarts that are visible. There can be more than one which share teh
same symbol (for instance due to recursion). You can pick one that
isn't the first one on the list, and then invoke-restart.

CLISP example session:

  $ clisp -q
  [1]> (compute-restarts)
  (#S(RESTART :NAME ABORT
      :TEST #<COMPILED-FUNCTION SYSTEM::DEFAULT-RESTART-TEST>
      :INVOKE-TAG NIL
      :INVOKE-FUNCTION #<COMPILED-FUNCTION SYSTEM::MAIN-LOOP-1-1>
      :REPORT #<COMPILED-FUNCTION SYSTEM::MAIN-LOOP-1-2>
      :INTERACTIVE #<COMPILED-FUNCTION SYSTEM::DEFAULT-RESTART-INTERACTIVE>
      :MEANINGFULP T))

Only one restart is visible from the repl.

Let's make an error to get into a nested error-recovery repl, then
see what restarts are visible:

  [2]> (+ "a" 3)

  *** - +: "a" is not a number
  The following restarts are available:
  USE-VALUE      :R1      Input a value to be used instead.
  ABORT          :R2      Abort main loop
  Break 1 [3]> (compute-restarts)
  (#S(RESTART :NAME ABORT
      :TEST #<COMPILED-FUNCTION SYSTEM::DEFAULT-RESTART-TEST>
      :INVOKE-TAG NIL
      :INVOKE-FUNCTION #<COMPILED-FUNCTION SYSTEM::BREAK-LOOP-2-1>
      :REPORT #<COMPILED-FUNCTION SYSTEM::BREAK-LOOP-2-2>
      :INTERACTIVE #<COMPILED-FUNCTION SYSTEM::DEFAULT-RESTART-INTERACTIVE>
      :MEANINGFULP T)
   #S(RESTART :NAME USE-VALUE
      :TEST #<COMPILED-FUNCTION SYSTEM::DEFAULT-RESTART-TEST> :INVOKE-TAG NIL
      :INVOKE-FUNCTION #<COMPILED-FUNCTION SYSTEM::CHECK-VALUE-5>
      :REPORT #<COMPILED-FUNCTION SYSTEM::CHECK-VALUE-3>
      :INTERACTIVE #<COMPILED-FUNCTION SYSTEM::CHECK-VALUE-4> :MEANINGFULP T)
   #S(RESTART :NAME ABORT
      :TEST #<COMPILED-FUNCTION SYSTEM::DEFAULT-RESTART-TEST>
      :INVOKE-TAG NIL
      :INVOKE-FUNCTION #<COMPILED-FUNCTION SYSTEM::MAIN-LOOP-1-1>
      :REPORT #<COMPILED-FUNCTION SYSTEM::MAIN-LOOP-1-2>
      :INTERACTIVE #<COMPILED-FUNCTION SYSTEM::DEFAULT-RESTART-INTERACTIVE>
      :MEANINGFULP T))

Now there are two restarts with the same name.  If we do
(invoke-restart 'abort), of course it will go to the innermost one.
But we can search the list of restarts for the other one and do
invoke-restart on the restart object.

> We can argue about whether the type should be part of the name: e.g.,
> if x:string shadows x:integer then does an arithmetic operation on x
> find x:integer or does it fail for incompatible types?  But this is a
> discussion at a different level.

I would not go farther than separation of function and value bindings.

Separate namespaces for strings and numbers seems ... hokey.

It erquires static typing, with no overloading. What if x is an integer in one
scope, and a string in another scope, and then we call foo(x) which is
overloaded for strings and integers.  Probably we resolve in favor of the inner
nesting. Then, of what value is the separation if we abandon it at the
slightest appearance of a problem. :)

>>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.)
>
> Your Lisp is showing 8-) ... "nested function" is not synonymous with
> "closure".

It can be if everything is downward. Downward funargs still close over
their lexical environment; they coach which arries the bindings,
however, turns into a pumpking when the closure tries to escape.

I'm only thinking of the downward situation in this whole thread;
whose main topic is non-local returns! Jumping out to a closure whose
creation environment is still active and which is not set up to try to
escape.

> 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].

Okay, forget Pascal then with these bizarre restrictions. Let's
pretend that "Pascal" really means "GNU C" (with its local functions).

http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

GNU C has real downard funargs, a.k.a. non escaping closures.

(I thought Pascal was like this; but if not, it's too broken to
warrant another thought.)

So your comment could have said "your GNU C is showing". :)

Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Is multi-level function return possible? noitalmost <noitalmost@cox.net> - 2014-03-10 15:46 -0400
  Re: Is multi-level function return possible? Kaz Kylheku <kaz@kylheku.com> - 2014-03-11 05:20 +0000
  Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-03-11 13:04 +0000
    Re: Is multi-level function return possible? Kaz Kylheku <kaz@kylheku.com> - 2014-03-11 22:15 +0000
      Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-03-13 17:05 +0000
        Re: Is multi-level function return possible? Bill Findlay <yaldnif.w@blueyonder.co.uk> - 2014-03-14 01:28 +0000
        Re: Is multi-level function return possible? Ivan Godard <ivan@ootbcomp.com> - 2014-03-13 18:32 -0700
          Re: Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-14 20:27 +0000
      Re: Is multi-level function return possible? George Neuner <gneuner2@comcast.net> - 2014-03-14 02:39 -0400
        Re: Is multi-level function return possible? Kaz Kylheku <kaz@kylheku.com> - 2014-03-14 21:34 +0000
          Re: Is multi-level function return possible? Marco van de Voort <marcov@toad.stack.nl> - 2014-03-14 22:59 +0000
        Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-03-16 17:19 +0000
          Re: Is multi-level function return possible? Marco van de Voort <marcov@toad.stack.nl> - 2014-03-16 18:39 +0000
          Re: Is multi-level function return possible? Andy Walker <news@cuboid.co.uk> - 2014-03-16 19:45 +0000
            Re: Is multi-level function return possible? Bill Findlay <yaldnif.w@blueyonder.co.uk> - 2014-03-17 16:15 +0000
              Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-03-18 17:36 +0000
                Re: Is multi-level function return possible? Andy Walker <news@cuboid.co.uk> - 2014-03-21 02:04 +0000
                Re: Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-21 02:50 +0000
                Re: design of PL/I, was Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-21 06:43 +0000
                Re: design of PL/I, was Is multi-level function return possible? noitalmost <noitalmost@cox.net> - 2014-03-26 14:16 -0400
                Re: exception catching in PL/I, was Is multi-level function return possible? "Robin Vowels" <robin51@dodo.com.au> - 2014-03-27 21:08 +1100
                Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-03-24 17:06 +0000
                Re: Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-24 20:01 +0000
                Re: Is multi-level function return possible? George Neuner <gneuner2@comcast.net> - 2014-03-26 04:00 -0400
                Re: Is multi-level function return possible? Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-03-27 01:58 +0100
                Re: Is multi-level function return possible? Stefan Monnier <monnier@iro.umontreal.ca> - 2014-04-07 14:48 -0400
                Re: Is multi-level function return possible? Andy Walker <news@cuboid.co.uk> - 2014-03-26 12:16 +0000
                Re: Is multi-level function return possible? Andy Walker <news@cuboid.co.uk> - 2014-03-26 17:34 +0000
                Re: history of C, was Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-27 00:05 +0000
      Re: Is multi-level function return possible? Bakul Shah <usenet@bitblocks.com> - 2014-03-15 10:28 -0700
    Re: Is multi-level function return possible? George Neuner <gneuner2@comcast.net> - 2014-03-14 02:44 -0400
      Re: Is multi-level function return possible? Marco van de Voort <marcov@toad.stack.nl> - 2014-03-14 19:38 +0000
      Re: Is multi-level function return possible? Kaz Kylheku <kaz@kylheku.com> - 2014-03-14 21:36 +0000
      Re: Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-14 21:47 +0000
        Re: Is multi-level function return possible? Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-03-15 13:34 +0100
      Re: Is multi-level function return possible? Ian Lance Taylor <ian@airs.com> - 2014-03-14 16:55 -0700
  Re: Is multi-level function return possible? George Neuner <gneuner2@comcast.net> - 2014-03-11 13:56 -0400
    Re: Is multi-level function return possible? federation2005@netzero.com - 2014-03-26 17:39 -0700
      Re: catch and throw, was Is multi-level function return possible? rpw3@rpw3.org (Rob Warnock) - 2014-03-27 04:23 +0000
        Re: catch and throw, was Is multi-level function return possible? Kaz Kylheku <kaz@kylheku.com> - 2014-03-27 05:44 +0000
        Re: catch and throw, was Is multi-level function return possible? Bakul Shah <usenet@bitblocks.com> - 2014-03-26 23:20 -0700
          Re: catch and throw, was Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-27 19:21 +0000
          Re: exception catching in PL/I "Robin Vowels" <robin51@dodo.com.au> - 2014-03-28 10:50 +1100
            Re: exception catching in PL/I Martin Ward <martin@gkc.org.uk> - 2014-04-16 14:32 +0100
          Re: catch and throw, was Is multi-level function return possible? mac <acolvin@efunct.com> - 2014-03-28 23:08 +0000
            Re: catch and throw, was Is multi-level function return possible? Ivan Godard <ivan@ootbcomp.com> - 2014-03-28 18:24 -0700
              Re: catch and throw, was Is multi-level function return possible? Kaz Kylheku <kaz@kylheku.com> - 2014-03-29 02:47 +0000
                Re: catch and throw, was Is multi-level function return possible? Ivan Godard <ivan@ootbcomp.com> - 2014-03-28 21:32 -0700
              Re: catch and throw, was Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-29 03:38 +0000
                Re: precise and imprecise, was catch and throw, was Is multi-level function return possible? Ivan Godard <ivan@ootbcomp.com> - 2014-03-28 22:12 -0700
            Re: catch and throw, was Is multi-level function return possible? Kaz Kylheku <kaz@kylheku.com> - 2014-03-29 02:07 +0000
              Re: catch and throw, was Is multi-level function return possible? Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2014-03-29 02:44 -0400
            Re: PL/I exceptions, was catch and throw, was Is multi-level function return possible? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-29 02:40 +0000
              Re: PL/I exceptions "Robin Vowels" <robin51@dodo.com.au> - 2014-03-30 01:58 +1100
      Re: catch and throw, was Is multi-level function return possible? George Neuner <gneuner2@comcast.net> - 2014-03-28 03:52 -0400
  Re: Is multi-level function return possible? Louis Krupp <lkrupp@pssw.com> - 2014-03-11 15:16 -0600
  Re: Is multi-level function return possible? noitalmost <noitalmost@cox.net> - 2014-03-15 12:21 -0400

csiph-web