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

Re: Properties & Methods [re:globs? tie-in]

Thread Previous | Thread Next
From:
Paul
Date:
April 9, 2003 09:04
Subject:
Re: Properties & Methods [re:globs? tie-in]
Message ID:
20030409160355.78600.qmail@web41209.mail.yahoo.com

--- Luke Palmer <fibonaci@babylonia.flatirons.org> wrote:
> > --- John Williams <williams@tni.com> wrote:
> > > No lexical hash elements.  bummer.
> > 
> > Speaking of which....
> > in P5, I always thought this was really wierd:
> > 
> >   my %h = ( a => 1, b => 2, c => 3 );
> >   print join " ",%h,"\n";
> >   { local $h{b} = "foo";
> >     print join " ",%h,"\n";
> >   }
> >   print join " ",%h,"\n";
> > 
> > prints
> > 
> >   a 1 b 2 c 3 
> >   a 1 b foo c 3 
> >   a 1 b 2 c 3 
> > 
> > [snip], how would you do that in P6?
> > Is that a temp thing? Is it as simple here as replacing local()
> > with temp? Or maybe let? (I still don't quite get let, either. :)
> 
> Yep. s/local/temp/.

Sweet.

> C<let> is neat.  The output from that if C<let> were involved would
> be:
> 
>    a 1 b 2 c 3 
>    a 1 b foo c 3 
>    a 1 b foo c 3 

Ding! The little light goes on! lol!!!
Funny how sometimes a little example is all you need (even though
you've seen fifty already....)

> But the output from this:
> 
>    my %h = ( a => 1, b => 2, c => 3 );
>    print join " ",%h,"\n";
>    { let $h{b} = "foo";
>      print join " ",%h,"\n";
>      fail;  # or die or (maybe) throw
>    }
>    print join " ",%h,"\n";
> 
> would be:
> 
>    a 1 b 2 c 3 
>    a 1 b foo c 3 
>    a 1 b 2 c 3 
> 
> That is, C<let> makes its changes permanent only if its scope was
> exited successfully.  It's implications are incredible when you
> consider exception safety (you get strong exception safety basically
> for free).
> 
> Plus a bunch of other things we haven't thought of yet.
> 
> Luke

*SWEET*!!

*Conditionally* temporal values!!!

I get it!

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com

Thread Previous | Thread Next


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