Article View: comp.lang.misc
Article #2807Re: composition of functions
From: Richard A. O'Keefe
Date: Wed, 20 Feb 1991 07:04
Date: Wed, 20 Feb 1991 07:04
27 lines
1407 bytes
1407 bytes
In article <1991Feb15.230112.2902@csrd.uiuc.edu>, bliss@sp64.csrd.uiuc.edu (Brian Bliss) writes:
> >the question was: how do I write a function
> typedef int i2ifn(int);
> i2ifn compose(i2ifn f, i2ifn g) { /* fill this in */ }
> >so that compose(f,g)(x) == f(g(x)).
> you say
> int (*f1)(), (*f2)();
> int retval (x) { (*f1)((*f2)(x));}
> int (*compose (f, g))()
> int (*f)(), (*g)();
> { f1 = f; f2 = g; return retval; }
Spare me days! This completely (almost definitively) misses the
point. If I do
fg = compose(f, g);
hk = compose(h, k);
the later call to compose() should not invalidate the earlier result!
This atrociously buggy pseudo-implementation *guarantees* that
compose(compose(f,g),h)(x)
will not work, which it would in a language with first-class functions.
--
Professional programming is paranoid programming
Technical Details
Message-ID:
<4801@goanna.cs.rmit.oz.au>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!usc!apple!uokmax!munnari.oz.au!goanna!okReferences:
<1991Feb8.191014.6430@spool.cs.wisc.edu> <1991Feb15.230112.2902@csrd.uiuc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!usc!apple!uokmax!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.misc Subject: Re: composition of functions Keywords: composition, function, first-class object Message-ID: <4801@goanna.cs.rmit.oz.au> Date: 20 Feb 91 07:04:05 GMT References: <1991Feb8.191014.6430@spool.cs.wisc.edu> <1991Feb15.230112.2902@csrd.uiuc.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 27