Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!think.com!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.misc Subject: Re: On whether C has first-class composable functions Message-ID: <25199:Feb801:33:1191@kramden.acf.nyu.edu> Date: 8 Feb 91 01:33:11 GMT References: <1991Feb6.161639.18311@spool.cs.wisc.edu> <12547:Feb621:05:4491@kramden.acf.nyu.edu> <1991Feb7.150537.9257@spool.cs.wisc.edu> Organization: IR Lines: 99 In article <1991Feb7.150537.9257@spool.cs.wisc.edu> quale@picard.cs.wisc.edu (Douglas E. Quale) writes: > Unfortunately, this doesn't solve the problem. Your `functions' are not > functions. What happens when I pass a Bernstein `function' to twalk(3c)?? ``Unfortunately, your bignum package doesn't solve the problem. Your `bignums' are not numbers. What happens when I pass a DECWRL bignum to getcwd()??'' The mistake here is the second statement. Bignums are numbers; they just aren't the same as C's integers. Similarly, anything supporting certain operations is a function; it doesn't have to be the same as C's functions. Your ``problem'' of passing a non-C-function to twalk() has been quite thoroughly addressed in other postings. Just because twalk() only accepts C functions doesn't mean that other functions aren't functions, either in theory or in practice. This has all been discussed to death before in this newsgroup. If you're trying to contribute something, make an effort to see what's already been contributed. > The question was NEVER, "Can C _implement_ dynamically allocable functions?" I chose the subject line (I choose most subject lines in comp.lang.misc these days) and I was using ``L has X'' to mean ``X can be implemented in L'' where L is a language and X is a semantic feature. Apparently people can't stand this usage, although nobody's been able to come up with any other sensible definition of ``has'' in this context; so I've stopped using ``has'' in this way. Nevertheless, that's what it means in the subject line. This has also been discussed to death before in this newsgroup. If you're trying to contribute something, make an effort to see what's already been contributed. > I can implement a Turing machine simulator in practically any language, > but it's not very interesting or useful. (Not in Fortran.) The reason that a Turing machine simulator isn't useful is that once you get down from theory to practice, you care about issues like efficiency. However, usefulness is not the same thing as power. Would you say that the original Forth doesn't have I/O facilities just because its I/O facilities aren't very useful? No. > Does C _have_ dynamically allocable functions? > No. What's your definition of ``has'' for a semantic feature? I'll bet that your definition will either be (1) syntactic, in which case you're confusing syntax and semantics; or (2) so ambiguous as to be useless; or (3) in agreement with mine. > Compose has a simple mathematical definition, and since Dan is so proud > of his math, he surely knows that (f o g) o h = f o (g o h). > (Strangely he expressed confusion over a nested call to compose in a > posting made by someone else some time ago, but this is really quite > elementary.) That call was improperly formed and nonsensical as both a mathematical expression and a C language expression. [ composing three functions in a row ] > Let's see Bernstein's compose function do that. Are you shooting from the hip, or are you simply confused? It is trivial to compose() twice in a row. > (On a related note, > he also claimed that it is just as easy to prove program correctness in > C as it is in a functional language. Well, no, that's not really what I claimed, but I'll let this slide. > Since his implementation of compose > in C doesn't obey one of the most trivial identities for that function, > I wonder how he reaches that bizarre conclusion.) You are simply confused. > P.S. Dan, read _The_Structure_and_Interpretation_of_Programming_Languages_, > by Abelson, Sussman and Sussman. Jim Giles said he didn't learn > anything useful from that book, but I certainly did and you might too. I second Jim's opinion. > At the very least it will show you what you can do with first-class > functions. (A short preview: blocks, delayed evaluation, > call-by-name, own variables, coroutines, non-local exits and > objects for OOP.) Ah! Finally you come down out of the fluff and get to some real issues. As I noted in the previous article, I have found very little use for first-class functions in real-world problems. All of the applications you mention can easily be handled in C---and some of them, such as coroutines and so-called ``objects,'' simply don't gain anything from first-class functions. ---Dan