home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!mailgzrz.TU-Berlin.DE!news
- From: carsten@pizza.fb10.tu-berlin.de (Carsten Schultz)
- Newsgroups: comp.lang.pascal
- Subject: Re: Passing functions as params in Turbo Pascal
- Date: 5 Jan 1993 16:51:35 GMT
- Organization: ZRZ/TU-Berlin
- Lines: 35
- Distribution: world
- Message-ID: <1iceanINN93n@mailgzrz.TU-Berlin.DE>
- References: <93005.015817JXU3@psuvm.psu.edu>
- Reply-To: carsten@pizza.fb10.tu-berlin.de (Carsten Schultz)
- NNTP-Posting-Host: pizza.fb10.tu-berlin.de
-
- In article <93005.015817JXU3@psuvm.psu.edu> <JXU3@psuvm.psu.edu> writes:
- > While ISO Standard Pascal (as defined by Jensen and Wirth) allows
- > passing functions as parameters to other functions or procedures,
- > Turbo Pascal 6.0 that I use at school, declares an error that an
- > identifier is expected, which means that I cannot pass functions
- > as parameters in the standard way. For all you TP experts on the
- > net, is there a workaround? e.g. something like defining pointers
- > to functions as one might do in C? Thanks in advance for any help
- > in this matter. I desperately need this feature, so that I don't
- > have to write a separate integration procedure for every function
- > I want to integrate.
- >
-
- Hi,
-
- I just give an example, please refer to the manual for details.
-
- function Ident(x: real): real; far;
- begin
- Ident:=x;
- end;
-
- type realFunc= Function(x: real): real;
-
- function Integrate(f: realFunc; a, b: real): real;
- begin
- Integrate:=(b-a)*(f(a)+f(b))/2;
- end;
-
-
-
- I did not test this.
- The above functions are useful for demonstration purposes only.
-
- Carsten
-