kend@data.UUCP (Ken Dickey) (01/09/91)
In comp.lang.misc you (Dan Bernstein) write: >In article <443@data.UUCP> kend@data.UUCP (Ken Dickey) writes: [Quote from Guy Steele] >> SCHEME also permits the treatment of functions as full flegded data >> objects; they may be passed as arguments, returned as values, made >> part of composite data structures, and notated as independent, unnamed >> ("anonymous") entities. {Contrast this with most ALGOL-like >> languages, in which a function can be written only by declaring it and >> giving it a name; imagine being able to use an integer value only by >> giving it a name in a declaration!). Dan>``Full-fledged data objects,'' yes; but ``first-class'' doesn't mean Dan>``full-fledged.'' Actually, they are synonymous in the literature. E.g.: the T Manual ** states Procedures are "full fledged" data objects in T while a paper on T language *** states procedures are "first-class citizens"; they may be stored ... [Same authors, same year]. The whole idea of being a full fledged or first-class citizen is having the maximal rights of citizenship. In most languages, integers are first class citizens. I don't have to name (declare) numbers before use, I can pass them as parameters, return them as results, I can generate new numbers in a fairly unconstrained way. Pointers are first-class data objects in C. I can take the address of any location I can specify, as many times as I want, etc. Functions in C are constrained in ways that do not allow them first class status. To quote from a previous missive: >Your definition of unnamed functions did not magically turn them into >function pointers. Either you are trying to return a function by value, >which is impossible in C without a *semantic* extension; or you are >returning a pointer to that function, in which case, as Karl said, the >pointer is useless after the return. Q.E.D. -Ken Dickey ================================================================ ** "The T Manual, Pre-release edition, 2nd Printing, 2 July 1982, Yale U., by Norman Adams andJonathan Rees. *** "T a Dialect of Lisp, or LAMBDA: The Ultimate Software Tool", Conference Record of the 1982 ACM Symposium on Lisp and Functional
mjs@hpfcso.HP.COM (Marc Sabatella) (01/29/91)
> > How do I > >dynamically allocate function objects in C?? > > Huh? How do you dynamically allocate NON-function objects in C?? > Answer: you use a library routine called malloc. So, all you need is a > routine called "falloc" in your library... > > While the implementation of falloc clearly can't be portable, the same > holds for malloc. Oh come on, this is silly. Besides the fact that it probably is in fact possible to write malloc() in C if you are on a Unix machine (ie, you have sbrk) despite handwaving about illegal pointer comparisons, there is a big difference here. The definition of malloc() is indeed portable - all standard C's have a malloc() with the same semantics. And the language defines a means for you to put data into the newly allocated memory. Neither of these is true for "falloc" - there is no standard definition for such a routine, and even if you wrote one, there is no way to compile code into falloc()'ed space.