On Friday, July 13, 2012 08:18:19 Gabor Szabo wrote:
>    method add {
>       say 'before';
>       @.add.push( 42 );

If I recall correctly, calling @.add() is the same as @(self.add). Calling a 
method recursively without ending is bound to go into an infinite loop :)

To avoid that you can call push on the attribute, directly, without going 
through the accessor method:

=== CODE ===
class A {
   has @.add;
   method add {
      say 'before';
      @!add.push( 42 );
      say 'ever after';
   }
}

A.new.add;

Which works without problems:
=== RESULT ===
before
ever after


Kind regards,
Tadeusz Sośnierz

Reply via email to