Python vs. Io

Daniel Ehrenberg LittleDanEhren at yahoo.com
Sat Jan 31 02:26:46 CET 2004


"Sean Ross" <sross at connectmail.carleton.ca> wrote
> Hi.
> I took a look at Io because of your post, and I have a question:
> 
> Are there prototype(?) _and_ instance methods/slots?
> 
> In other words, is there a shared state mechanism between instances of a
> prototype?
> If so, could you show an example.
> 
> Thanks,
> Sean

I'm not sure how to tell you this so I'll just give a heavily
commented example (comments in Io are with #, //, or /* */)

parentProto := Object clone //makes parentProto a new object
//:= is used for creating new variables
parentProto shared := 5 //parentProto's new slot shared holds 5
parentProto different := 6
parentProto sum := method(shared + different) //self isn't necessary
write("parentProto's sum: ", parentProto sum, "\n")
x := parentProto clone //essentially new instance of parentProto
y := parentProto clone
x different = 2 //just updating slots is done with =.
y different = 3
write("first x sum ", x sum, "\n",
      "first y sum ", y sum, "\n")
parentProto shared = 7 //should show up on all clones
write("later x sum", x sum, "\n",
      "later y sum", y sum, "\n")

Does that illustrate it well? I know the difference between := and =
is annoying, but you'll get used to it, and it allows really cool
things to be done with scopes and inheretance.

Daniel Ehrenberg



More information about the Python-list mailing list