[comp.object] Closures in C? WAS: Objective-C Review

edwardj@microsoft.UUCP (Edward JUNG) (06/30/90)

In article <12396@june.cs.washington.edu> jmaloney@cs.washington.edu (John Maloney) writes:
>In reply to Brad Cox's statement:
>> what about a C-based varient of Smalltalk Blocks?
>
[...]
>What I'm suggesting is that programs like HyperCard would not need to
>supply a "HyperTalk" language if they could use C++ or Objective-C as the
>customization languague. Smalltalk and Lisp already allow this. It is harder
>to achieve in the C-based OOP dialects because:
>    a) the compiler is not usually part of the run-time system, and
>    b) symbol table information needed for variable bindings is often
>
There are a couple reasons that this is difficult (true closures in
a C language).  To implement closures, you need to carry the
environment around with you.  In Smalltalk you can do this since
essentially the stack frames are saved and garbage collected like
any other object.

Note that I am saying "difficult", not "impossible".  It may be
more in the domain of where Brad Cox places Objective-C rather
than the stricter and more performance-oriented C++ world.

This is really hard to do in C, especially with file scoping semantics
that are presently supported.  You can fake closures in a primative
manner; NeXT did this with their "target/action" paradigm in NeXTStep.
You can do something very similar in C++, although due to static
typing requirements, you'd want to have parameterized classes.

Moreover I would argue that making C the end-user customization
language is a mistake.  I don't mean to demean users, but a large
fraction of "interesting" users might have a problem with learning
C (or learning any language with a large cognitive gap from their
native language, e.g. English, Japanese, French, or whatever they
are comfortable with).

>I would thus like to add "dynamic compilation and binding" to the wish-list.
>
>	-- John

Dynamic binding is a larger issue; blocks are only a part of this.

Implementing closure-like semantics without the full generality
can be done along language stack frame restrictions without any
trouble.  In some ways DLL-like functionality is like this, just
without the object and protocol-based orientation.

jmaloney@cs.washington.edu (John Maloney) (07/03/90)

edwardj@microsoft.UUCP (Edward JUNG) suggests:
>Implementing closure-like semantics without the full generality
>can be done along language stack frame restrictions without any
>trouble.  In some ways DLL-like functionality is like this, just
>without the object and protocol-based orientation.

Sorry, Edward, I don't know what "DLL-like functionality" is nor
do I understand exactly what implementation you propose. Can
you explain? It sounds as though one restriction would be that
blocks could not be returned from functions. Is that right?

	-- John