develooper Front page | perl.perl6.language | Postings from April 2003

RE: Delayed Assignments, was Re: Fun with multi-dimension arrays

Thread Previous
From:
Austin Hastings
Date:
April 26, 2003 20:57
Subject:
RE: Delayed Assignments, was Re: Fun with multi-dimension arrays
Message ID:
ICELKKFHGNOHCNCCCBKFIECGCEAA.Austin_Hastings@Yahoo.com


> -----Original Message-----
> From: Dave Whipp [mailto:dave@whipp.name]
> Sent: Saturday, April 26, 2003 10:48 PM
> To: perl6-language@perl.org
> Subject: Delayed Assignments, was Re: Fun with multi-dimension arrays
> 
> 
> Following up my own post, I wrote::
> 
> >   method update
> >   {
> >      locally_hypothesise @.grid; # what keyword?
> > 
> >      for @.grid.fully_flat_iterator -> $iter
> >      {
> >         .value = $self.next_state(.key)
> >      }
> >   }
> > 
> > and next state will use the old values for @.grid:
> 
> The solution is really quite simple, and needs no extra suff in the 
> core. All we have to do is redefine the infix:= operator in the 
> local scope:
> 
>    method update
>    {
>        my @assigs is keep { $_[0]=$_[1] for @assigns }
>        my sub infix:=($lhs is rw, $rhs) { push @assigns, [$lhs, $rhs] };
> 
>        for @.grid.fully_flat_iterator
>        {
>           .value = $self.next_state(.key)
>        }
>    }
> 
> Wrap that up in a C<delayed_assignments> module, et voila, were're done: 
> transaction style updates.


And somehow you think this is SIMPLER than creating @new_grid?

=Austin

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About