Article View: comp.lang.misc
Article #2607Re: On whether C has first-class composable functions
From: Norman Graham
Date: Mon, 07 Jan 1991 15:41
Date: Mon, 07 Jan 1991 15:41
53 lines
2824 bytes
2824 bytes
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
<norman@a.cs.okstate.edu> Standard Disclaimer Applies
{cbosgd,rutgers}!okstate!norman
Technical Details
Message-ID:
<1991Jan7.154111.5166@d.cs.okstate.edu>Path:
arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!uokmax!d.cs.okstate.edu!normanReferences:
<1991Jan07.045733.13637@dirtydog.ima.isc.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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