David J. Goehrig | 11 Feb 18:03 2009

CREATE DOES> & objects [ was objects and forth ]

On Wed, Feb 11, 2009 at 01:12:15PM +0100, Frédéric DUBOIS wrote:
> I've read several times that the CREATE ... DOES> structure is a primitive form of objet. 
> Since it has no CREATE DOES>, how does one does closures with CF?

Well remember that in colorforth (and forth in general), since you can 
redefine a word, any definition is effectively a closure.  So you don't
even need CREATE DOES> to imply closures.

Remeber that the return stack is actually a continuation stack.  The value
placed on the return stack is the current continuation of the word being
executed.  In effect, forth works like lisp where every function call
has an implict callcc and the bound function pushed on a global stack.
When you combine the dictionary's innate closures, w/ run time compilation, 
and a continuation stack, you have all the pre-requisites for OO programming:
encapulation, protection, ad hoc polymorphism, parametric polymorphism,
message sends, subtyping, etc.

When you come right down to it, you can say forth is object oriented, and
it has just one base object type known as the cell.   All of the base
words in your forth VM are methods that operate on cells.  And all of 
the characterization of subclasses is based upon the words you write to
operate on them.  Building a complex object heirarchy is left to the 
programmer as an exercise.  

If you're thinking in OO terms, CREATE DOES> is an object factory, that
produces new top level objects.  It effectively serves the same purpose
of a class side instance creation method.  It simply provides  you with
a simple syntax to parameterize object creation.