Xref: utzoo comp.lang.c:36616 comp.lang.functional:659 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!sarah!bingnews!kym From: kym@bingvaxu.cc.binghamton.edu (R. Kym Horsell) Newsgroups: comp.lang.c,comp.lang.functional Subject: Re: function composition in C Message-ID: <1991Feb28.072757.1904@bingvaxu.cc.binghamton.edu> Date: 28 Feb 91 07:27:57 GMT References: <6873@munnari.oz.au> Organization: State University of New York at Binghamton Lines: 34 In article acha@CS.CMU.EDU (Anurag Acharya) writes: >In article <6873@munnari.oz.au> aet@felix.ee.mu.OZ.AU (bert) writes: >> Does anyone know how to write a compose function in C, >> without writing a Scheme interpreter to do it in. >Nope. it is possible. >int compose (foo,bar,baz) >int (*foo) (); >int (*bar) (); >int baz; >{ > return ((*foo) ((*bar)(baz))); > } I don't think anyone was saying your method was not valid, but functional composition returns a _function_ given two other functions. This enables you to, e.g., assign the said composition to another function variable. Can you write something like: int (*proc1)(int); int (*proc2)(int); int (*my_composition)(); my_composition = compose(proc1,proc2); so that later you can say: printf("%d\n",(*my_composition)(1)); There will be a problem (for a start) with the type for `compose()'. If you can handle that one there are a few more examples I have in mind (where the composed functions include local variables). -kym