Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!samsung!crackers!jjmhome!smds!sw From: sw@smds.UUCP (Stephen E. Witham) Newsgroups: comp.lang.misc Subject: Re: On whether C has first-class composable functions Summary: Not an interpreter, but not peaches and cream either. Message-ID: <311@smds.UUCP> Date: 30 Jan 91 16:29:05 GMT References: <3576:Jan2622:55:2991@kramden.acf.nyu.edu> <6800@exodus.Eng.Sun.COM> Organization: SMDS Inc., Concord, MA Lines: 45 brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >In article <21245@yunexus.YorkU.CA> oz@yunexus.yorku.ca (Ozan Yigit) writes: >> Yes, you were able to write an interpreter that contained said >> functionality, minus the scoping details. >> Amazing. >'Twas hardly amazing. What amazes me is that there are *still* people >posting to this newsgroup asking questions like ``Ya know, I haven't >seen any portable first-class composable function implementations that >don't have arbitrary limits. Is this because they are impossible, or is >there some sneaky way?'' ... At least we have the extremes of the opinion spectrum covered. The things I've seen (and posted) here are neither "interpreters" nor "first-class" (nor "obvious," as someone said, and Dan agreed). "Interpreter" implies a big mechanism that you have to write, that uses a different internal representation, requires a different kind of thinking to use, runs slowly, and is hard to interface to routines in the "host" language. The functionoids we've been talking about, on the other hand, are not that different from things people regularly do in C. The syntax of using them is, well, close to the syntax of using regular C functions. They deal in regular C data types. They run with compiled code, and not a lot of overhead, either. And there's no big mechanism that has to be implemented or added to your program. "First-class," in my favorite interpretation (i.e., relative to the rest of the language), also doesn't apply to these functionoids. In C, all variable- sized data are second-class compared to the simple, fixed-sized data types. They can't be put in "automatic" variables or be intermediate values in expressions, so you have to take care of allocating and freeing their space. Also, these functionoids can't be used interchangeably with regular C function pointers. I don't think that's a big practical limitation, but it is something function pointers can do that functionoid pointers can't. Calling this stuff obvious is an insult. Great, so you guys already knew the answer. I remember the time when I didn't, and the time when I first started using this stuff in a real C program (and it ran faster than the assembly- language program it replaced). Objects and lexical closures are standard stuff in computer science now, but for some of us lowly coders, the fact that you can get the same effects relatively painlessly in C is a nifty, non-obvious idea. --Steve Witham Not-the-fault-of: SMDS, Inc., Concord, MA