Salvador Mirzo <
smirzo@example.com> wrote or quoted:
I've read the Early History of Smalltalk, by the way. I think I
understand what he means by ``messaging'', ``local retention and
protection'' and ``hiding of state-process''. My knowledge reaches its
limits a bit in ``extreme late-binding of all things'' and I get
certainly puzzled in ``it can be done in Smalltalk and in LISP'' given
that he is ``not aware of [others]''.
Object-oriented programs contain expressions to describe the sending
of messages at runtime. Here's an example of such an expression:
o s: x
. "o" is the receiver object, "s" the selector (keyword) of the
message, and x is an argument.
"Extreme late-binding of all things" to me (S. R.) means
that it is possible to give the the values of "o" and "x"
(including their types) only as late as immediately before
"o s: x" is being evaluated (executed).
Now, to address my main puzzle. The email is from 2003. Alan Kay was
certainly aware of Python, Java and so on. Why would his notion of OOP
be impossible in Python or Java?
He might have some criteria he has not mentioned.
For example, in Smalltalk, blocks of code are objects, too,
and you can define your own custom bool type and "if" statement
using Smalltalk and such blocks. Maybe he requires that, in
an object-oriented language, blocks of code are objects, too. [1]
In LISP, you can have code values using "LAMBDA", and maybe
that's the criterion Alan Kay used, as both Smalltalk and LISP
have code block as run-time values.
In Python and in Java there also are non-object-oriented features,
and maybe he requires that, in an object-oriented programming
language, everything has to be done in an object-oriented way;
what might be called a "/pure(ly)/ object-oriented language".
Maybe he requires metaclasses. Well, Python has them!
[1]
So, you define two classes "True" with
ifTrue: aBlock
^aBlock value
and "False" with
ifTrue: aBlock
^nil
. Now we have implemented an if statement using polymorphism
that can be used as:
a > 0 ifTrue: [a := 0]
. I have not checked this code on a Smalltalk implementation.
Maybe it needs some additions or modifications, but it gives
the general idea.
An attempt to emulate this in Python:
main.py
class True_:
def if_true( self, block ):
exec( block )
class False_:
def if_true( self, block ):
pass
class Boolean_:
def __new__( self, value ):
return True_() if value else False_()
a = -2; Boolean_( a < 0 ).if_true( "print( 'It is true!' )" )
a = +2; Boolean_( a < 0 ).if_true( "print( 'It is true!' )" )
output
It is true!
. I used "exec" to emulate block objects, one could also use
"lambda" (but it is restricted in Python) or a form of "def".