function composition in C

Lou Kates louk at tslwat.UUCP
Wed Mar 6 14:48:39 AEST 1991


In article <91060.132635REIDMP at MAINE.BITNET> REIDMP at MAINE.BITNET (Reid M. Pinchback) writes:
>gwyn at smoke.brl.mil (Dough Gwyn) writes:
>* >I don't think anyone was saying your method was not valid, but functional
>* >composition returns a _function_ given two other functions.
> 
>* Which makes this topic unsuitable for discussion in the C newsgroup.
>* In C, functions are always statically defined.
> 
>Isn't it a bit abrupt to forestall questions in this manner?  One of
>the joys of reading newsgroups like this is to have the chance to
>consider problems that we haven't thought of before; 

Perhaps we need  to consider  what you   need to add to C to  get
this with the minimal change to C.

You should be able to do function composition in OO extensions to
C. In particular, consider the class C, each of whose objects has
the publicly settable function pointers fp  and gp and the method
c(x) which   returns  f(g(x))  where f  and g  are the  functions
pointed at by fp and gp.

Then the composition of f and g  can be constructed by creating a
new object  of class C, setting the function pointers to point to
f and g and returning a function pointer to c.

Can this be  done  in C++? Objective  C? other OO extension to C?
Assuming that this works, code this in  an OO extension to C that
operates as a preprocessor to C and look at the generated C code.
What is that has been added that allows this to work?

Lou Kates, Teleride Sage Ltd., louk%tslwat at watmath.waterloo.edu



More information about the Comp.lang.c mailing list