MC: As I go about Learning XOTcl, I decided to wikify some of my questions as I find answers to them to help others in the future. Feel free to add & expand on this page.
Q: What's the equivalent idiom for what snit would call type variables (or static member variables)?
A: On the XOTcl mailing list I received helpful answers from Neophytos Demetriou, Kristoffer Lawson, and Gustaf Neumann. Summarizing here:
Class Chapters Chapters set current_chapter 12345 # Then any object or class can use Chapters set current_chapter # while an instance could do: Chapters aChapter [aChapter info class] set current_chapter 4567 puts [[aChapter info class] set current_chapter] # We can a printCurrentChapter method (an instproc on the Chapters class) as: Chapters instproc printCurrentChapter {} { puts [[my info class] set current_chapter] } # and we call the method aChapter printCurrentChapter
Another possibility is to bring the classes variable into the scope of a method on an object.
Chapters instproc incrChapter {} { [self class] instvar current_chapter incr current_chapter } aChapter incrChapter
Gustaf in particular pointed out that XOTcl does not need a special construct, since every class is an object as well, and variables kept in a class are nothing special. Note that a programmer can decide which kind of class he is refering to:
The type of variable you are refering to is the first one.
XOTcl in prototyping mode XOTcl for prototyping