passing procedures as arguments for another procedure in Turbo pascal 
Author Message
 passing procedures as arguments for another procedure in Turbo pascal

Pascal running on our school's Unix system accepts procedures and
functions as argument for other procedures and functions. However Turbo
Pascal does not accept this. My question is : is there a pascal compiler
for the PC that accepts this ????



Mon, 01 Mar 1999 03:00:00 GMT  
 passing procedures as arguments for another procedure in Turbo pascal


Quote:
NL> writes:

>Pascal running on our school's Unix system accepts procedures and
>functions as argument for other procedures and functions. However Turbo
>Pascal does not accept this. My question is : is there a pascal compiler
>for the PC that accepts this ????

?? I'm running BP7 which does take procedures & functions as arguments, but
as far as I remember all the TP's did?  See the current thread for
FirstThat/LastThat problems which I'm having in passing local procs for
some code on how to do it.

The manual I think covers typed procedures if, like me, you're not too good
at assembly.



Mon, 01 Mar 1999 03:00:00 GMT  
 passing procedures as arguments for another procedure in Turbo pascal


Quote:
>Pascal running on our school's Unix system accepts procedures and
>functions as argument for other procedures and functions. However Turbo
>Pascal does not accept this. My question is : is there a pascal compiler
>for the PC that accepts this ????

Are you defining things correctly?  Last time I checked, I could do
functions as arguments.  Procedures OTOH, can't be done.  For a
function, one might do...

function add2numbers(num1, num2: integer):integer;
  begin
      add2numbers := num1 + num2;
  end;

function sub2numbers(num1, num2: integer): integer;
  begin
     sub2numbers := num1-num2;
  end;

begin
    writeln(sub2numbers(15, add2numbers(3,2)));
end.

writeln is a procedure.....as you see the others are functions....

Untested....but if you coded that up, it should return 10.
It (should) work because the compiler sees those functions as returned
values...and not functions...as you see above, the add2numbers
function returns an integer, which is exactly what is needed for the
2nd item of sub2numbers....



Mon, 01 Mar 1999 03:00:00 GMT  
 passing procedures as arguments for another procedure in Turbo pascal




Quote:

>>Pascal running on our school's Unix system accepts procedures and
>>functions as argument for other procedures and functions. However Turbo
>>Pascal does not accept this. My question is : is there a pascal compiler
>>for the PC that accepts this ????

>Are you defining things correctly?  Last time I checked, I could do
>functions as arguments.  Procedures OTOH, can't be done.  For a
>function, one might do...

>function add2numbers(num1, num2: integer):integer;
>  begin
>      add2numbers := num1 + num2;
>  end;

>function sub2numbers(num1, num2: integer): integer;
>  begin
>     sub2numbers := num1-num2;
>  end;

>begin
>    writeln(sub2numbers(15, add2numbers(3,2)));
>end.

>writeln is a procedure.....as you see the others are functions....

>Untested....but if you coded that up, it should return 10.
>It (should) work because the compiler sees those functions as returned
>values...and not functions...as you see above, the add2numbers
>function returns an integer, which is exactly what is needed for the
>2nd item of sub2numbers....

That is, indeed, not calling a function variable but a function result.

Both procedure and function variables can be parameters to a procedure
or function (probably even recursively?), BUT they must be declared FAR.
This means that they must appear in an interface section OR be declared
in the {$F+} state OR include the FAR; pseudo-statement.      All AFAIR.

BTW, only works for genuine functions and procedures.  Things like Odd,
from ? the System unit, are not really genuine; the compiler short-cuts.

BTW, you're in the wrong newsgroup; should be c.l.p.borland

--

     http://www.merlyn.demon.co.uk/      Inbound E-mail is/was sticky.



Mon, 01 Mar 1999 03:00:00 GMT  
 passing procedures as arguments for another procedure in Turbo pascal


Quote:
>That is, indeed, not calling a function variable but a function result.

Just mistook what the person was asking....
Referencing procedure variables may be evidenced at
http://www.geocities.com/Paris/3537/pascal17.txt

The main section can very easily be coded up as a procedure, minus the
logic assigning the procedure to pass the proper compute procedure
through.  A good case for doing procedure vars in other procedures may
be for a sort where the user may request things be sorted in different
ways by different items of say a record set...define the sort, fit the
proper compare logic in with a procedure variable from another
procedure and do it that way...

Quote:
>Both procedure and function variables can be parameters to a procedure
>or function (probably even recursively?), BUT they must be declared FAR.
>This means that they must appear in an interface section OR be declared
>in the {$F+} state OR include the FAR; pseudo-statement.      All AFAIR.

Yes, they must be declared FAR or the compiler is incapable of
understanding what is happening....


Tue, 02 Mar 1999 03:00:00 GMT  
 passing procedures as arguments for another procedure in Turbo pascal


Quote:
> Pascal running on our school's Unix system accepts procedures and
> functions as argument for other procedures and functions. However Turbo
> Pascal does not accept this. My question is : is there a pascal compiler
> for the PC that accepts this ????

GNU Pascal accepts this.

See: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/
     ftp://kampi.hut.fi/jtv/gnu-pascal/

    Peter


home address:  D\"usseldorfer Str. 35, 45145 Essen, Germany
         WWW:  http://agnes.dida.physik.uni-essen.de/~peter/



Tue, 02 Mar 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. passing procedures as arguments for another procedure in Turbo pascal

2. passing procedures as arguments for another procedure in Tu

3. Passing values to Assembly procedures in Turbo Pascal

4. Passing a pointer to a procedure/function as a parameter in a procedure

5. Variable length argument list procedure?

6. Procedures with varying number of arguments

7. Declaring variable number of arguments in a function or procedure

8. assert10.zip Assert procedure for Turbo Pascal 4+

9. Turbo Pascal 5.5 Large Drive Function/Procedure

10. rdates10.zip Turbo Pascal File Functions and Procedures

11. Passing parameters to stored procedure.

12. Passing TMemoField as a TStringList parameter to a procedure

 

 
Powered by phpBB® Forum Software