home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / pascal / 7869 < prev    next >
Encoding:
Internet Message Format  |  1993-01-05  |  1.6 KB

  1. Path: sparky!uunet!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!mailgzrz.TU-Berlin.DE!news
  2. From: carsten@pizza.fb10.tu-berlin.de (Carsten Schultz)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Passing functions as params in Turbo Pascal
  5. Date: 5 Jan 1993 16:51:35 GMT
  6. Organization: ZRZ/TU-Berlin
  7. Lines: 35
  8. Distribution: world
  9. Message-ID: <1iceanINN93n@mailgzrz.TU-Berlin.DE>
  10. References: <93005.015817JXU3@psuvm.psu.edu>
  11. Reply-To: carsten@pizza.fb10.tu-berlin.de (Carsten Schultz)
  12. NNTP-Posting-Host: pizza.fb10.tu-berlin.de
  13.  
  14. In article <93005.015817JXU3@psuvm.psu.edu> <JXU3@psuvm.psu.edu> writes:
  15. > While ISO Standard Pascal (as defined by Jensen and Wirth) allows
  16. > passing functions as parameters to other functions or procedures,
  17. > Turbo Pascal 6.0 that I use at school, declares an error that an
  18. > identifier is expected, which means that I cannot pass functions
  19. > as parameters in the standard way.  For all you TP experts on the
  20. > net, is there a workaround? e.g. something like defining pointers
  21. > to functions as one might do in C?  Thanks in advance for any help
  22. > in this matter. I desperately need this feature, so that I don't
  23. > have to write a separate integration procedure for every function
  24. > I want to integrate.
  25.  
  26. Hi,
  27.  
  28. I just give an example, please refer to the manual for details.
  29.  
  30. function Ident(x: real): real; far;
  31. begin
  32.   Ident:=x;
  33. end;
  34.  
  35. type realFunc= Function(x: real): real;
  36.  
  37. function Integrate(f: realFunc; a, b: real): real;
  38. begin
  39.   Integrate:=(b-a)*(f(a)+f(b))/2;
  40. end;
  41.  
  42.  
  43.  
  44. I did not test this.
  45. The above functions are useful for demonstration purposes only.
  46.  
  47. Carsten
  48.