Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: function composition in C Message-ID: <10666@dog.ee.lbl.gov> Date: 6 Mar 91 14:15:15 GMT References: <6873@munnari.oz.au> <1991Feb28.072757.1904@bingvaxu.cc.binghamton.edu> <15357@smoke.brl.mil> <91060.132635REIDMP@MAINE.BITNET> <347@tslwat.UUCP> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 32 X-Local-Date: Wed, 6 Mar 91 06:15:15 PST In article <347@tslwat.UUCP> louk@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@ee.lbl.gov