user-pic

chrisarg

  • About: I like to use Perl for material other than text.
Subscribe to feed Recent Actions from chrisarg

  • Brett Estrade commented on Caching & Memoization with state variables

    I love state variables, but oddly only use them when creating sub based state machine xD - which is typically just for show. But the idea of co-routines in Perl is nifty.

    I think E. Choroba means something like:

    sub foo {
      state $foo = 1;
      ...
      say $foo;
      ++$foo;
    }
    
    

    foreach my $i (1 .. 10) {
    foo();
    }

    versus,

    my $foo = 1;
    foreach my $i (1 .. 10) {
      my $sub = sub {
        my $myfoo = $foo;
        ...
        say $myfoo;
      };
      ++$foo;
      $sub->();
    }
    
  • E. Choroba commented on Caching & Memoization with state variables

    No, I mean we only have one subroutine, but we want to use it to generate two different sequences.

Subscribe to feed Responses to Comments from chrisarg

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.