Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!think!rose From: rose@think.ARPA (John Rose) Newsgroups: net.lang.c Subject: Re: Pointers to freshly minted functions Message-ID: <4954@think.ARPA> Date: Fri, 11-Apr-86 10:18:19 EST Article-I.D.: think.4954 Posted: Fri Apr 11 10:18:19 1986 Date-Received: Sun, 13-Apr-86 07:43:19 EST References: <728@petsd.UUCP> <1486@devwrl.DEC.COM> Reply-To: rose@think.UUCP (John Rose) Followup-To: net.lang.c Distribution: net Organization: Thinking Machines, Cambridge, MA Lines: 25 Summary: Submitted code creates new functions on the Vax I have posted to net.sources a small utility which allows creation of new functions, called ``closures''. I've already posted this code, at the end of a lengthy article on closures in Lisp and C, but I suspect that few people made it to the end of that article. So, since the topic is still alive, and for the sake of concreteness, you can look at the code. Here's an example of what it can do: typedef double (*PFD)(); extern PFD make_myexp(/* double base */); /* make_myexp is implemented with malloc, _init_closure, * and a `base function' which calls exp. */ PFD Exp, Exp10, Exp2; /* Each call mallocs a new function object: */ Exp = make_myexp(2.71828183); Exp10 = make_myexp(10.0); Exp2 = make_myexp(2.0); /* Now, pow(x,10.0) == (*Exp10)(x) == Exp10(x) */ -- ---------------------------------------------------------- John R. Rose Thinking Machines Corporation 245 First St., Cambridge, MA 02142 (617) 876-1111 X270 rose@think.arpa ihnp4!think!rose