Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!olivea!decwrl!shelby!neon!robert From: robert@Neon.Stanford.EDU (James R. Kennedy) Newsgroups: comp.lang.c Subject: Re: function composition in C Message-ID: <1991Mar2.224617.2613@Neon.Stanford.EDU> Date: 2 Mar 91 22:46:17 GMT References: <6873@munnari.oz.au> <9754@uwm.edu> Organization: Computer Science Department, Stanford University Lines: 29 In article <9754@uwm.edu> markh@csd4.csd.uwm.edu (Mark William Hopkins) 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. > > > >A call should look something like this: > > (compose(sqr,cube)) (2) > >which would evaluate to 64. > ... > > You could do it compile-time like this example for composing x^2 and > 2*x: > [... code deleted ...] Everyone seems to have ignored an important issue that harks back to yet another major war on the structure of C, namely the "typeof()" debate. I don't want to restart it here, but I do want to point out that the solution proposed in the parent to this article as well as the solution proposed by the person who suggested storing compositions as structs and using an "apply" function work only for one type. I had the impression that the author of the original article was looking for a type-independent way to do function composition in C, since to my mind, THAT is the main thing allowed by the obvious Scheme construct but utterly unavailable in C. Robert Kennedy Department of Computer Science Stanford University