[Edu-sig] PySqueak: "Self" as the source of many ideas in Squeak
Ian Bicking
ianb at colorstudy.com
Sat May 6 23:35:05 CEST 2006
Paul D. Fernhout wrote:
>>> I think that Ian's suggestion is the most sensible strategy for
>>> proceeding
>>> in that direction and continuing to maintain community interest in a
>>> PySqueak inclined towards Self-like prototypes and a related GUI for
>>> constructivist educational use (and other general use as well).
>>> And if metaclasses turn out to not be the best approach,
>>> still anything simple which preserves the Python syntax
>>> while giving the new features (say, having all prototypes inherit from
>>> a common class which overrides __getattr__ and __setattr__ to
>>> simply look into the instance to find data and behavior?)
>> I think it could be easier than that. I think a lot of the more
>> declarative programming I do really has prototypes underneath it.
>> (Ironically in Javascript I never find a need for prototypes, except to
>> simulate classes.)
>
> Of course, you probably don't have a Self-like environment for Javascript.
> :-) Or is there one? I've never done much with JavaScript.
There are some more sophisticated development environments for
Javascript, but I've never used any of them, only source editing.
> Anyway, I tried to follow your example, but I am still left confused as to
> how it is easier than creating GUI tools that manipulate all instances of
> just one Prototype class? Your example still seems focused on making
> classes. With one class, a few lines of code to search for values through
> parent slots and you're done? Essentially, for any prototype-ish work, one
> would just work with instances of this one class. Am I missing somethgin
> vital here? Are you thinking about one class per one prorotype object? Is
> that for performance reasons?
I think my example confused you, since "class" was a misnomer. That is,
you *can* subclass non-classes using the class statement. I was using
that to mean "clone and update". I.e.:
class foo(bar):
def spam(self): print 'hi'
That means "clone bar, and set foo.spam to this function". The use of
the class statement is a little confusing, which is why I would like a
make statement.
To get to mechanics, basically this class statement means:
foo = bar.__metaclass__('foo', (bar,), {'spam': spam_func})
So with the right fiddling you can "subclass" an instance. Anyway, I
like the syntax, and find it more comfortable than direct assignment
(especially for methods).
For direct assignment, you might find the "magic_set" decorator I wrote
useful: http://svn.colorstudy.com/home/ianb/ruby_blocks.py (toward the
bottom)
It lets you do:
@magic_set(foo)
def spam(self): print 'hi'
which handles the closure to add instance methods directly to instances
(which doesn't work if done just through assignment), among other
assignments. It uses the name of the first argument (self, cls, or
anything else) to determine what kind of function you are trying to create.
--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
More information about the Edu-sig
mailing list