Re: Is multi-level function return possible?

noitalmost <noitalmost@cox.net>
Sat, 15 Mar 2014 12:21:52 -0400

          From comp.compilers

Related articles
[15 earlier articles]
Re: Is multi-level function return possible? kaz@kylheku.com (Kaz Kylheku) (2014-03-14)
Re: Is multi-level function return possible? gah@ugcs.caltech.edu (glen herrmannsfeldt) (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? ian@airs.com (Ian Lance Taylor) (2014-03-14)
Re: Is multi-level function return possible? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2014-03-15)
Re: Is multi-level function return possible? usenet@bitblocks.com (Bakul Shah) (2014-03-15)
Re: Is multi-level function return possible? noitalmost@cox.net (noitalmost) (2014-03-15)
Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (2014-03-16)
Re: Is multi-level function return possible? marcov@toad.stack.nl (Marco van de Voort) (2014-03-16)
Re: Is multi-level function return possible? news@cuboid.co.uk (Andy Walker) (2014-03-16)
Re: Is multi-level function return possible? yaldnif.w@blueyonder.co.uk (Bill Findlay) (2014-03-17)
Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (2014-03-18)
Re: Is multi-level function return possible? news@cuboid.co.uk (Andy Walker) (2014-03-21)
[9 later articles]
| List of all articles for this month |
From: noitalmost <noitalmost@cox.net>
Newsgroups: comp.compilers
Date: Sat, 15 Mar 2014 12:21:52 -0400
Organization: Compilers Central
References: 14-03-020 <cM0i1n00k1AptjU01M0ju3>
Keywords: code, Pascal, comment
Posted-Date: 16 Mar 2014 14:02:46 EDT

On Tuesday, March 11, 2014 09:04:57 AM Anton Ertl wrote:
> 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
> feature of the language, and Wirth removed it (along with goto) from
> his later languages.


I had to go look that up. Yep, it's there in the ISO standard, as one of the
uses of goto. This is kind of like what I had in mind. I was thinking of a
prettier syntax, though:
procedure f() :
    procedure g() int :
        procedure h() :
            return from g 3;
        end h;


        h();
        nope(); # doesn't get called
    end g;


    x : int;
    x := g();
    print x; # prints 3
end p;


The syntax meshes nice with my break stmt:
while {outer} x < 10 :
    loop :
        break from outer;
    end;
end;


It's a lot more restrictive than exeptions, and I'm not sure if has any use,
but it looks nice :)
The only potential use that comes to mind is:
procedure p() :
    procedure r() :
        cond : bool; # some condition
        break from r if cond;
        r();
    end r;
end f;


f();


The break would cause a quick exit by blowing away all the intervening stack
frames from the recursive calls to r.


I'm assuming I can implement this without too much trouble, since it could be
done in Pascal. Is that true?
[I would think so. See the next message. -John]


Post a followup to this message

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