Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!edcastle!aiai!jeff From: jeff@aiai.ed.ac.uk (Jeff Dalton) Newsgroups: comp.lang.lisp Subject: Re: Why aren't CL functions 1st class objects? Message-ID: <3477@skye.ed.ac.uk> Date: 2 Oct 90 17:35:01 GMT References: <1990Sep13.202219.21047@oracle.com> <3437@skye.ed.ac.uk> <3806@goanna.cs.rmit.oz.au> <3450@skye.ed.ac.uk> Reply-To: jeff@aiai.UUCP (Jeff Dalton) Organization: AIAI, University of Edinburgh, Scotland Lines: 87 In article peter@ficc.ferranti.com (Peter da Silva) writes: >In article <3450@skye.ed.ac.uk> jeff@aiai.UUCP (Jeff Dalton) writes: >> - Objects have the right to remain anonymous. >> - Objects have an identity that is independent of any >> names by which they may be known. >> - Objects can be stored in variables and data structures >> without losing their identity. >> - Objects may be returned as the result of a procedure call. >> - Objects never die. >> This too is true of functions in Common Lisp (with a possible quibble >> on identity as in the FLET and EQ example in my previous article). >It appears that this is true of functions in C, and I wouldn't want to >argue that C has first-class functions. If you look in the IEEE Scheme standard, you'll see a definition of "first class" that has only two clauses, both satisfied by (pointers to) functions in C. (I forget the details, and it was a draft I was reading, not the final standard. Anyway, it was probably something like: can be the value of a variable and can be returned as a result. Passed as a parameter probably comes under the value of a variable clause.) In any case, I'm not sure what point you're trying to make. If what you're thinking is that the above isn't really a good definition of "first-class", then I would, of course, be interested in a better one. Both the list above and the previous list I posted (from the Pop Design Philosophy) received the same complaint (this time from you, last time from Richard O'Keefe), namely that it would be true of functions in C. Nonetheless, they are typical of the lists one finds in the literature. So what is wrong? I can think of several possibilities: 1. The people who wrote these lists got it wrong. 2. The people applying the lists to C have got it wrong. For example, perhaps the lists aren't really true of functions in C but only of pointers to functions. 3. "First-class" doesn't imply all that we sometimes think it does. I think there's something to be said for all of these, but right now I'll just talk about (1). Another source for claims about "first class" is Stoy's book on denotational semantics. He says something about what "first class" means, and gives some examples, but does not (if I recall correctly) try to condense the definition into a neat little list or "bill of rights". One of the examples is a function that returns a function. It may have been a definition of composition, but I'm not sure. In any case, compose can be written in Scheme or Common Lisp; it cannot be written in (portable) C. I suspect that the lists of rights have this sort of thing in mind when they talk about objects being "returned as results". That would mean that the lists are basically right but haven't quite managed to express this particular idea. Of course, there's still a problem here, because compose (and similar functions) can be written in old-fashioned Lisp, the sort that supposedly doesn't have first class functions. I can see two ways to deal with this objection. (1) These definitions cheat in some way. (2) Those Lisps don't really have *functions* (or procedures) let along first-class ones. Of these, I think more can be said for the first. >(the anonymity clause can be satisfied by packing the object away in a file, >making it static, and having it returned by a function of known name that's >global within that file) Can you really pack the function (as opposed to the pointer to it) away in a file? But why go to such lengths? Why not just stick it in an array or something? Anyway, in C all functions are defined as named, even though they can (in a sense) be separated from their names later one. Not so in Scheme where functions might originate as anonymous lambda- expressions. I don't know if this is really the right difference, but at least it's a difference. -- Jeff