Python vs. Io
Daniel Ehrenberg
LittleDanEhren at yahoo.com
Fri Jan 30 20:26:46 EST 2004
More information about the Python-list mailing list
Fri Jan 30 20:26:46 EST 2004
- Previous message (by thread): Python vs. Io
- Next message (by thread): Python vs. Io
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"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
- Previous message (by thread): Python vs. Io
- Next message (by thread): Python vs. Io
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list