Calling a procedure within a procedure 
Author Message
 Calling a procedure within a procedure

I've got several procedures in my program and they are all calling other
procedures. However i've found that i can only call another procedure if that
procedure is physically located above that procedure which causes big problems
as its also calling another procedure.

E.g.
Procedure1
Procedure2- call procedure 4
Procedure 3 -call procedure1, call procedure 2
Procedure4-call procedure 5
Procedure5-END.



Sat, 06 Sep 2003 16:28:37 GMT  
 Calling a procedure within a procedure

Quote:

>I've got several procedures in my program and they are all calling other
>procedures. However i've found that i can only call another procedure if that
>procedure is physically located above that procedure which causes big problems
>as its also calling another procedure.

>E.g.
>Procedure1

procedure 4 [exactly same parameter definition as below]; FORWARD;

Quote:
>Procedure2- call procedure 4
>Procedure 3 -call procedure1, call procedure 2

procedure 5 [exactly same parameter definition as below]; FORWARD;
Quote:
>Procedure4-call procedure 5
>Procedure5-END.



Sat, 06 Sep 2003 16:42:52 GMT  
 Calling a procedure within a procedure

Quote:

> I've got several procedures in my program and they are all calling other
> procedures. However i've found that i can only call another procedure if that
> procedure is physically located above that procedure which causes big problems
> as its also calling another procedure.

> E.g.
> Procedure1
> Procedure2- call procedure 4
> Procedure 3 -call procedure1, call procedure 2
> Procedure4-call procedure 5
> Procedure5-END.

Why not sort them as follows?
procedure1
procedure5
procedure4
procedure2
procedure3

Mind you, I'm aware of the fact (as Marco van de Voort suggested)
using FORWARD may be a simpler way out (and, indeed, the only way
out, when the calls between procedures form cycles, e.g. proc1
calling proc2, proc2 calling proc3 and proc3 calling proc1).

Has it actually happened to somebody that using FORWARD was absolutely
necessary? Any such calls must obviously be conditional, for otherwise
you get an endless loop.

--
Jyrki Lahtonen, docent
Department of Mathematics,
University of Turku,
FIN-20014 Turku, Finland

http://users.utu.fi/lahtonen
tel: (02) 333 6014



Sat, 06 Sep 2003 17:52:28 GMT  
 Calling a procedure within a procedure

Quote:


>procedure4
>procedure2
>procedure3

>Mind you, I'm aware of the fact (as Marco van de Voort suggested)
>using FORWARD may be a simpler way out (and, indeed, the only way
>out, when the calls between procedures form cycles, e.g. proc1
>calling proc2, proc2 calling proc3 and proc3 calling proc1).

>Has it actually happened to somebody that using FORWARD was absolutely
>necessary? Any such calls must obviously be conditional, for otherwise
>you get an endless loop.

Yes, very often. Parsers often need forward defined procedures.

Forward can also be handy for scope reasons in some isolated cases, since it
allows you to define the procedure implementation further down.



Sat, 06 Sep 2003 18:07:20 GMT  
 Calling a procedure within a procedure

Quote:
> Has it actually happened to somebody that using FORWARD was absolutely
> necessary? Any such calls must obviously be conditional, for otherwise
> you get an endless loop.

Yes, had to do with recursive programming which did not fit in one
procedure.

But I also use FORWARD for an other reason nowadays. I try to give
functions/procedures a name which tell me what they do like "AddToFile". But
if this proc uses the function "ReadFromD64", I have to place it above the
first one. With a few procedures and functions that's no problem. But with a
lot of them I use FORWARD to put them in alphabetical order. Until now I
have no troubles with it like loose of speed etc.

If someone thinks it has disadvantages, please let me know.

Groetjes, Ruud

http://Ruud.C64.org/



Sat, 06 Sep 2003 19:22:22 GMT  
 Calling a procedure within a procedure

Quote:
>procedure 4 [exactly same parameter definition as below]; FORWARD;

What do you mean by parameter definition? I'm not sure what the parameter is!


Sat, 06 Sep 2003 23:19:27 GMT  
 Calling a procedure within a procedure

Quote:

>>procedure 4 [exactly same parameter definition as below]; FORWARD;

>What do you mean by parameter definition? I'm not sure what the parameter is!

Example: (this is NOT possible, the compiler will complain)

procedure xxx(s:string;y:integer); forward;

[..]

procedure xxx(s:string;y:longint);



Sat, 06 Sep 2003 23:22:15 GMT  
 Calling a procedure within a procedure


Quote:

>>>procedure 4 [exactly same parameter definition as below]; FORWARD;

>>What do you mean by parameter definition? I'm not sure what the parameter is!

>Example: (this is NOT possible, the compiler will complain)

>procedure xxx(s:string;y:integer); forward;

>[..]

>procedure xxx(s:string;y:longint);

One can also omit the parameters from the actual definition. In
Standard Pascal one has to omit them.

Osmo



Sun, 07 Sep 2003 00:43:52 GMT  
 Calling a procedure within a procedure


However i've found that i can only call another procedure if that

Quote:
>procedure is physically located above that procedure which causes big
problems
>as its also calling another procedure.

in pascal, everyting has to be defined before you can use it. when looking
at the source code, everything above has been defined, and everything below
has yet to be defined (as a general rule!)

it is good that way, it helps us think structure, rather than a complete
mess



Sun, 07 Sep 2003 02:15:13 GMT  
 Calling a procedure within a procedure
OK - thanks! it works now!


Sun, 07 Sep 2003 03:34:45 GMT  
 Calling a procedure within a procedure


Tue, 20 Mar 2001 11:52:28 :-

Quote:

>Has it actually happened to somebody that using FORWARD was absolutely
>necessary? Any such calls must obviously be conditional, for otherwise
>you get an endless loop.

As a professional mathematician, you might not find my longcalc.pas (via
sig line 3) of interest.  But it does need FORWARD (which, naturally, I
only use when inevitable) :

function RPN(const St : string ; var SP : PLET) : boolean ; forward ;

RPN evaluates the string St, which contains operands to be pushed and
operators to use them (does arithmetic, bases 2..16, up to >65000
digits).  It calls subroutines to do most of its work, and these call
others, including subroutines for operators.

Simple operators like "add" are implemented in pure Pascal, but more
complicated ones like "#ge" (date of Gregorian Easter for given year),
or "#pi" (pi by the BBP method), or conversion between Y M D h m s and
(UNIX) time_t, are themselves implemented as strings to be evaluated by
RPN.

Thus there must be at least one FORWARD in the single-file program.

In a Unit, the Interface section provides declaration before use.

Web authors may be more interested in checklinx.pas, same place; it
reads local DOS copies of Web pages to find local links and follows them
to check any anchors and reads the pages to ..., except that it
remembers what it has done and does not repeat.  That too uses FORWARD,
in recursion.

In demime.pas, I seem to use FORWARD to declare a procedure "FAIL" early
so that other procedures may call it without having access to a global
variable used in FAIL; but this may be a bad (but working) program.

And countdwn.pas, a Vorderman emulator (UK TV), has procedures P, Q, R
calling each other; hence P is FORWARD.

And envicalc.pas recurses like longcalc (but is a smaller program,
usable but unfinished).

IMHO, FORWARD is, according to circumstances, either undesirable or
indispensable.

--

 Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
 PAS, EXE in <URL: http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
 Do not Mail News to me.    Before a reply, quote with ">" or "> " (SoRFC1036)



Sun, 07 Sep 2003 06:57:42 GMT  
 Calling a procedure within a procedure

Quote:
> Has it actually happened to somebody that using FORWARD was absolutely
> necessary? Any such calls must obviously be conditional, for otherwise
> you get an endless loop.

Several people have now convinced me that e.g. clean parsing routines
require
this. Thanks to Dr Stockton for the link - so that's what professional
code looks like. I'm impressed. As I always write code for a single
purpose,
I never had to learn all those directives and conditional defines. I
think
I could learn to use them simply by studying your code, though.

--
Jyrki Lahtonen, docent
Department of Mathematics,
University of Turku,
FIN-20014 Turku, Finland

http://users.utu.fi/lahtonen
tel: (02) 333 6014



Sun, 07 Sep 2003 14:40:45 GMT  
 Calling a procedure within a procedure

Quote:




>>>>procedure 4 [exactly same parameter definition as below]; FORWARD;

>>>What do you mean by parameter definition? I'm not sure what the parameter is!

>>Example: (this is NOT possible, the compiler will complain)

>>procedure xxx(s:string;y:integer); forward;

>>[..]

>>procedure xxx(s:string;y:longint);

>One can also omit the parameters from the actual definition. In
>Standard Pascal one has to omit them.

A lot of new compilers don't support this, because it clashes with
overloading.


Tue, 09 Sep 2003 04:36:57 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Calling Procedures within Inline Assembly?

2. Calling packaged procedures from within Delphi

3. Using a Procedure within a Procedure?

4. HELP - calling a Procedure from with a Procedure??

5. HELP - Calling a procedure from within a procedure - how??

6. Dynamic WHERE clause in Stored Procedures within INTERBASE ?

7. Granting Interbase privledges from within a stored procedure

8. How to declare Interrupt procedures within objects ?

9. Executing a Sybase Stored Procedure within Delphi

10. PChar Params For Stored Procedure Calls

11. Stored Procedure cannot be called from Delphi App

12. Calling front-end procedure from server SQL-trigger

 

 
Powered by phpBB® Forum Software