suppose I want this behaviour : 

sub new_counter($start=0) { 
    my     $cnt = $start;
    my sub incr { 
                  ++$cnt;
                };       
    my sub decr {   
                  --$cnt;
                };
    return sub (str $how="incr")
           {      
                given $str { 
                 when /incr/ &incr ;
                 when /decr/ &decr ;
           }
}

and then "has" allows me to do that .


sub new_counter($start=0) { 
    has     $cnt = $start;
    
    has sub cnt { 
                    $cnt;
                };       
    has sub incr { 
                  ++$cnt;
                };       
    has sub decr {   
                  --$cnt;
                };
    return 1; # this is "1" with properties 
}

and then : 

our $cnt = new_counter ;

$cnt.incr 
$cnt.decr 
$cnt.cnt 


this does not seem to give second unrelated meaning to "has".
but, actually, I dont know .


arcadi 


Reply via email to