Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!ceres.physics.uiowa.edu!news.iastate.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!cs.uiuc.EDU!johnson From: johnson@cs.uiuc.EDU (Ralph Johnson) Newsgroups: comp.object Subject: Re: What are closures? Message-ID: <1991Mar14.161424.5659@m.cs.uiuc.edu> Date: 14 Mar 91 16:14:24 GMT References: <1991Mar8.061042.5578@tukki.jyu.fi> Sender: news@m.cs.uiuc.edu (News Database (admin-Mike Schwager)) Reply-To: johnson@cs.uiuc.EDU (Ralph Johnson) Organization: University of Illinois Lines: 50 Piercarlo says: |> Strictly speaking, a closure is a persistent reusable denotable "first |> class" context. |> |> In many languages contexts (aka environemt frames) are not denotable or |> persistent or reusable; each procedure instance creates a new implicit |> context for that invocation. |> |> Closure is at times used by extension to indicate the whole of a |> persistent reusable denotable procedure instance, but while accepting |> the convention I would like to insist that more properly it is only the |> context therein. |> |> In the debate you have been following some have insisted (me, for |> example :->) that an object in most OO languages is a persistent |> denotable reusable lexical context shared by all the methods for that |> object. This certainly explains our confusion. We have different definitions of closure. Piercarlo says that a closure is a context. I have always been told that it was a procedure bound with a context. There is a big difference. The difference is that the only operation on a closure is to evaluate it, while a context acts like a dictionary, i.e. you can look up the values of symbols bound in it and change them. You can implement objects with closures (i.e. as a procedure bound to a context). Scheme programmers do it all the time. However, this is not the normal way to think of an object. On the other hand, an object is obviously a context. Thus, my argument with Piercarlo was caused by his nonstandard use of the word "closure". Contexts are records. Closures are procedure-like thingees with a private state. Contexts are simple to understand. Closures are complicated. (This isn't really fair, but I am on a roll!) Claiming that objects are contexts is no big deal, while claiming that they are closures certainly is. By the way, Smalltalk has both contexts and closures. In fact, it has many kinds of contexts. Each object is a context, of course. There is a class "MethodContext" that represents stack frames. Further, Dictionary is a kind of context that is used by application programs. Smalltalk blocks are closures (well, the truth is a little more complicated). If you take a Self-like view of the world, even methods are closures. However, objects ARE NOT closures. Ralph Johnson -- University of Illinois at Urbana-Champaign