🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.ada
Article #891

Procedure/function parameters

#891
From: andy
Date: Tue, 15 Jul 1986 17:46
52 lines
1911 bytes
Forgive my pascal-eze, but the following partial program is quite
difficult to implement in Ada(TM) without drastic changes.  Generics
don't work because both top level procedures have state; reinstantiating
either loses that state.  Passing a tag that says which procedure to
call (the enumeration scheme) doesn't work; the procedures being
passed are not visible to the called procedure (and besides, they
refer to variables of private types that the called procedure
shouldn't know about).

Notice how simple the procedure parameter solution is.  (I reused
names to discourage Ada implementations that change the scope of
various names.  A real program might use distinct names but still
want to maintain separate scopes.)

I recently wrote a compiler where I used procedure parameters
extensively because they allowed me to maintain local state.  Without
this local state, the program would not have been understandable.

procedure a (procedure b (procedure c));
type foo : <something>;
var bar : foo;

procedure c;
begin	{c}
<manipulate bar>
end;	{c}

begin	{a}
<init bar>
b(c);
<manipulate bar>
end;	{a}

procedure b;	{intential name reuse throughout}
type foo : <something>;
var bar : foo;

procedure c (procedure a);
begin	{c}
a;
<manipulate bar>
end;	{c}

begin	{b}
<init bar>
a(c);
<manipulate bar>
end;	{b}

-andy
decwrl!glacier!shasta!andy
andy@sushi.stanford.edu
Technical Details
Message-ID: <679@Shasta.STANFORD.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utcs!mnetor!seismo!caip!nike!oliveb!glacier!Shasta!andy

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utcs!mnetor!seismo!caip!nike!oliveb!glacier!Shasta!andy
From: andy@Shasta.UUCP
Newsgroups: net.lang.ada
Subject: Procedure/function parameters
Message-ID: <679@Shasta.STANFORD.EDU>
Date: Tue, 15-Jul-86 13:46:40 EDT
Article-I.D.: Shasta.679
Posted: Tue Jul 15 13:46:40 1986
Date-Received: Wed, 16-Jul-86 08:55:09 EDT
Reply-To: andy@Shasta.UUCP (Andy Freeman)
Organization: Stanford University
Lines: 52