home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / pascal / 4489 < prev    next >
Encoding:
Text File  |  1992-07-21  |  1.2 KB  |  46 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!math.fu-berlin.de!zrz.tu-berlin.de!cs.tu-berlin.de!veit
  3. From: veit@opal.cs.tu-berlin.de (Veit Zimmermann)
  4. Subject: Re: Functions and Procedures as Parameters
  5. Message-ID: <1992Jul21.203545.1907@cs.tu-berlin.de>
  6. Sender: news@cs.tu-berlin.de
  7. Organization: Techn. University of Berlin, Germany
  8. References: <BrpxpG.351@ux1.cso.uiuc.edu>
  9. Distribution: fb20
  10. Date: Tue, 21 Jul 1992 20:35:45 GMT
  11. Lines: 33
  12.  
  13. husak@ux1.cso.uiuc.edu (Stephen R. Husak ) writes:
  14.  
  15. >I've been trying to implement the following in TP5.5... Could someone
  16. >either clue me in or tell me if it is possible.
  17. >
  18. >I want to pass a function into another function:
  19. >
  20. >eg --    function First(a,b: real;
  21. >               function test(x:integer):integer);
  22. >    
  23. >    { rest of function follows }
  24. [stuff deleted]
  25. You're lucky
  26. I did this two days ago. It goes like this:
  27. First you must declare a FunctionType e.g. :
  28.     Type TestFunc = FUNCTION (x : INTEGER) : INTEGER;
  29.  
  30. Now you are able to do this :
  31.     FUNCTION First (a, b : REAL; 
  32.             test : TestFunc) : INTEGER;
  33.     BEGIN
  34.       first := test (TRUNC (a*b));
  35.     END;
  36.  
  37. Calling First goes simply like this :
  38.     First (x, y, TrueTester);
  39.  
  40. with     TrueTester (x : INTEGER) : INTEGER;
  41.  
  42. Hope this helps
  43.  
  44.         CIAO
  45.             veit    [zimzim@marie.physik.tu-berlin.de]
  46.