|
From: Arnulf W. <ar...@wi...> - 2008-06-15 12:03:43
|
Am Sonntag, 15. Juni 2008 13:08:43 schrieb Donal K. Fellows:
> Will Duquette wrote:
> > Arnulf Wiedemann wrote:
> >> I think I have not yet fully understood, how that will work.
> >>
> >> For example: class cat has a variable cat_color defined and I have
> >> 2 objects which have as object class cat and these are named cat1
> >> and cat2. Will variable cat_color be shared between the objects? So
> >> if I set cat1 cat_color to black with a class method, will a class
> >> method of cat2 get back black as cat_color?
> >>
> >> Are object specific variables also accessible by class methods?
> >
> > I am curious about this point as well. As I read it, normal variables
> > declared by class cat are instance variables; cat1 and cat2 do not
> > share values. However, variables can also be declared by the class
> > using "self"; in this case, the variable is a "typevariable" in Snit
> > parlance. Is that correct?
> >
> > Will such class variables be visible without declaration or
> > qualification in instance methods? (I'd presume so.)
> >
> > And I presume that class and instance variables declared by ancestors
> > will also be accessible, but *with* qualification (mechanism clearly
> > to be fleshed out later)?
>
> This TIP is about making instance variables available in methods without
> explicitly having to bring them in for each method. Class variables as
> such don't exist (the 'self' path leads to instance variables on the
> class objects) but you can link variables using [upvar] so that should
> not be a big problem. It's orthogonal to this TIP (at the moment).
>
> All instance variables will be available through [my variable], wherever
> they are declared (or even if they aren't declared at all). I don't want
> to do name mangling or other concealment if I can avoid it.
>
That looks ok for itcl as far as I can see at the moment. Will method speak2
work as I have written it (see below)?
Arnulf
> Perhaps an example will be more helpful:
>
> namespace path oo
> class create animal {
> variable utterance
> constructor says {
> set utterance $says
> }
> method speak {} {
> puts $utterance
> }
> }
> class create cat {
> superclass animal
> constructor {} {
> next Meow
> }
method speak2 {} {
puts $utterance
}
> }
> class create dog {
> superclass animal
> constructor {} {
> next Woof
> }
> variable utterance
> method speak {} {
> set word [lindex $utterance 0]
> set utterance [lrepeat [expr {3-[llength $utterance]}] $word]
> next
> }
> }
> cat create Tiddles
> dog create Fido
>
> With that, we would then get this:
>
> % Tiddles speak
> Meow
% Tiddles speak2
Meow
> % Fido speak
> Woof Woof
> % Tiddles speak
> Meow
> % Fido speak
> Woof
> % Fido speak
> Woof Woof
>
> Donal.
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Tcl-Core mailing list
> Tcl...@li...
> https://lists.sourceforge.net/lists/listinfo/tcl-core
|