Board index » delphi » Pass Functions into Function

Pass Functions into Function

Does anyone know how to pass functions as function parameters in Borland
Pascal 7? I wrote a simple program, but I could not get it to compile.
What is wrong with my code? Thanks in advance.

program test;
        type
                MathFunc = function (x: real): real;

        function dot (f, g: MathFunc, x: real): real;
        begin
                dot := f(x)  * g(x);
        end;

begin
        writeln (dot (sin, cos, 5));
end.

--
K...@SEAS.UCLA.EDU
http://www.seas.ucla.edu/~kin
===============================================================================
"#define QUESTION ((bb) || !(bb))  - Shakespeare."
===============================================================================

 

Re:Pass Functions into Function


In article <DBnD98....@seas.ucla.edu>,

Quote
Kin Lau <k...@cloudburst.seas.ucla.edu> wrote:
>Does anyone know how to pass functions as function parameters in Borland
>Pascal 7? I wrote a simple program, but I could not get it to compile.
>What is wrong with my code? Thanks in advance.

>program test;
>    type
>            MathFunc = function (x: real): real;

>    function dot (f, g: MathFunc, x: real): real;
>    begin
>            dot := f(x)  * g(x);
>    end;

>begin
>    writeln (dot (sin, cos, 5));
>end.

Function parameters must be far, and can't be in the system unit.  If you had,
say, "function MySin(X: real): real; far" and similarly MyCos(), then
"dot(MySin, MyCos, x)" would work just fine.
--

http://www.armory.com/~jon                       Personal and Technical Pages
http://www.armory.com/~jon/hs/HomeSchool.html Home School Resource Pages

Other Threads