Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!uokmax!d.cs.okstate.edu!norman From: norman@d.cs.okstate.edu (Norman Graham) Newsgroups: comp.lang.misc Subject: Re: On whether C has first-class composable functions Message-ID: <1991Jan7.154111.5166@d.cs.okstate.edu> Date: 7 Jan 91 15:41:11 GMT References: <1991Jan07.045733.13637@dirtydog.ima.isc.com> Organization: Oklahoma State University Lines: 53 From article <1991Jan07.045733.13637@dirtydog.ima.isc.com>, by karl@ima.isc.com (Karl Heuer): > In article <1991Jan6.171234.27734@d.cs.okstate.edu> norman@d.cs.okstate.edu (N orman Graham) writes: > >>[The example should work, since it uses the *values* of f and g.] > > It's not f and g that are being used beyond their storage duration, it's the > anonymous function itself. I see. You assumed Lennart did not add function values to the language when he added anonymous functions; I assumed he did (after all, that _is_ the most natural assumption :-). > If C had Pascal-like nested functions, like > int beta(int x) { > int alpha(void) { return x; } > return alpha(); > } > I would consider "alpha" to be an object of type function that has automatic > storage duration, and hence becomes invalid when it goes out of scope. So > int (*gamma(int x))(void) { > int alpha(void) { return x; } > return α > } > is illegal for the same reason as my earlier example. Making alpha an > anonymous function does not change the situation. If functions are not first-class values in this new language, then you are correct. However, if functions (not function pointers) are first- class values in this new language, then your first example works and your second example is incorrect (as you have already noted). > Of course, you can also consider a further extension in which functions are > allocatable; but I was rebutting the statement "you cannot add unnamed > functions in a natural way without getting the additional semantic power". Now we've returned to the original point in the thread: C does not have first-class functions--It has first-class function pointers. It appears that you believe Lennart added anonymous function pointers to the language rather than anonymous functions. Anonymous function pointers are not as useful as anonymous functions (for example, see the failures of anonymous function pointers in the above examples). I believe Lennart was using the example of anonymous functions to hammer home the fact that first-class function pointers are not as useful or as general as first-class functions. -- Norman Graham Standard Disclaimer Applies {cbosgd,rutgers}!okstate!norman