function composition in C

James R. Kennedy robert at Neon.Stanford.EDU
Sun Mar 3 08:46:17 AEST 1991


In article <9754 at uwm.edu> markh at csd4.csd.uwm.edu (Mark William Hopkins) writes:
> In article <6873 at munnari.oz.au> aet at 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



More information about the Comp.lang.c mailing list