function composition in C
Chris Torek
torek at elf.ee.lbl.gov
Thu Mar 7 00:15:15 AEST 1991
In article <347 at tslwat.UUCP> louk at tslwat.UUCP (Lou Kates) writes:
>Perhaps we need to consider what you need to add to C to get
>this with the minimal change to C.
Probably such consideration belongs in alt.lang.cfutures, but since
alt.* groups have weaker propagations...:
>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.
This only works for a single return type. Since the type system in
any C-like language is infinitely extensible (each new `struct' is a new
type, for instance), either the composition function must be polymorphic
(choose your favourite other word here for `accepts arbitrary types')
or else you must resort to trickery, e.g., `the machine internally has
only this many types'.
The problem continues (only more so) for binding of arguments, e.g.,
there is no good way to define a function:
; compose takes a function f of $k$ arguments, a function g of
; one argument, and arguments $x_1 .. x_k$, and produces a new
; function of one argument which is equivalent to
; (f (g arg) x1 x2 ... xk).
You might as well give in and use Scheme. :-)
--
In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427)
Berkeley, CA Domain: torek at ee.lbl.gov
More information about the Comp.lang.c
mailing list