Larry Wall writes:
Larry Wall writes:
 > 
 > I guess the real question would be, is it an overall simplification to
 > allow "has" anywhere?  There *is* an object out there representing each
 > abstract closure (pre-instantiation), but it's a bit of a stretch from
 > "Every block is a closure" to "Every block is a closure that is also
 > an object except that the object in question doesn't participate in
 > the closure's closure, as it were."
 > 

after reading this I realize that current meaning of "has" is really
quite strange... I would rather call it "serve" ( see below ) 

one  can think  of class / object attributes in
the following way ( I have in mind plan9 notion of every process
having its own vision of the namespace , ( and every block / closure
in perl _is_ in some sence process ) ) :



object attributes : persistent lexical variables . 
       Class _multiplexes_ them to each
       object and each object have its own private instance of it . 

class attributes :  persistent lexical variables . 
          Class serve the same copy of it  to all its 
                    subs/methods 

so class is in  some sence a server of a namespace . 


Class Foo {

has $foo ;  # persistent lexical variable 
serve $bar; # every instance of Class Foo will have its own private
            # version of $bar 
# or may be this. 
multiplex $bar; 
...

}

so now is clear _who_ "has" and "serve" : the surrounding closure (
marked by "Class Foo" _has_  ( persistent )  $foo lexical and it _serve_ $bar
instance to each object . 

since its all about ( lexical ) namespaces ... 

method "new" return an object to which class serve its ( own ) private 
copy of all variable marked by "serve" ( or multiplex ??? )

I dont know how classes and objects work now inside  , but probaly 
in the spirit of "class is just ...." any block which have some sort
of label / mark ( and Class Foo is just one of that kind ) may have a
"new" method . in that case the thing returned have private copyes of
variables labeled by "serve" and access to all "has" variable and 
methods/subs defined inside. 

counter: {
    has $a;
    serve $.cnt; 
    my  sub count(){ .cnt++ }     
    my  sub new() { $a++ ; ret new counter } 
}

$x = counter.new ; 
$x.count ;

just ( veryy fuzzy ) thoughts ...
sorry for this mess ... 

arcadi

Reply via email to