🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by John Stephens Wed, 11 Nov 1992 18:59
NAMELESS FUNCTIONS
#667
Author: John Stephens
Date: Wed, 11 Nov 1992 18:59
44 lines
2327 bytes
I'm trying to write a function that accepts a one variable math function
(double argument, double return type) and returns another math function
which will calculate the derivative of the original function argument.
In other words, the following will be possible:

        double (*dsqrt)(double) = derivative(sqrt);
        cout << dsqrt(x);

The main problem I am running into is that it seems to be impossible for
the returned function to know what function calculate the derivative
for because it only accepts one argument, and the derivative function
has no way of setting the function inside the calculating function!
(Does anyone understand what I'm trying to say?)

I was thinking of somehow doing it with classes, which would be much
easier. The usage would be as follows:

        Function f(sqrt);
        cout << f.derivative(10);

Or, of course, I could write a general derivative function that accepts
a one variable math function and a double value and just return the
derivative at that point. But I would still like to be able to do it the
way I stated originally. One thing that would solve the problem would be
a modified version of C/C++ that would allow the following:

        double (*derivative(double (*f)(double)))(double)
          {
          double derivCalc(double x)
            {
            ...calculate and return the derivative of f(x)...
            }
          return derivCalc;
          }

It would allow functions to be defined within other functions and use
all of their local variables, without having them explicitly entered as
arguments. In other words, each derivCalc returned could access a
different version of f. Unfortunately I think this is impossible in C
and C++, but who knows.

John Stephens
john.stephens@uttsbbs.uucp
                   
Re: NAMELESS FUNCTIONS
#1108
Author: Danny R Dalal
Date: Tue, 17 Nov 1992 21:04
6 lines
734 bytes
Are you trying to curry fucntions?
If you can generalize it without a high efficiency penalty, that would
be very usefull.


___Dan
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads