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."
 > 
 > On the other hand, it's the block itself that is that abstract
 > pre-closure object, so running it the other way would mean stretching
 > our minds into thinking "has" always sets block properties, and that
 > every object is a funny kind of block.
 > 

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 (
soryy, may be its too handwaving, but I have in mind plan9 notion of
every process having its own vision of the namespace , ( and every
block / closure in perl is sort of process ) ) :

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

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

so class is in  some sence a server of a ( lexical ) namespace . 


Class Foo {

has $foo ;  # persistent lexical variable -- class attribute 

serve $bar; # every instance of Class Foo will have its own private
            # version of $bar -- object attribute

# or may be this. 
multiplex $bar; # but this is longer 
...

}

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

since its all about ( lexical ) namespaces ... 

method "new" return an object to which class serve a 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++ ;  # a counter of counters 
                    ret new counter ; # this a default "new" method 
                  } 
}

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

just ( veryy fuzzy ) thoughts ...

arcadi

Reply via email to