If you've ever used a symbolic math program like Maple, Mathematica, or Mathcad, you're probably familar with this idea already. If not, then consider that using := is similar to an algebric statement; that is, if I say "$y := $x - 5", then y will ALWAYS being x - 5 until I redefine it or it goes out of scope.
A better example would be how to use this to simplify conversions from a database when needed. Without lazy evaluation:
With lazy eval:while ( my ( $name, $height, $weight ) = $sth->fetchrow_array() ) { my $ratio = $height/$weight; send_to_html( $name, $ratio ); }
This may not seem as powerful now, but there's a lot of potental for it.my ( $name , $height, $weight ); my $ratio := $height/$weight; # I would presure that # this would need to be # done under -w/strict send_to_html( $name, $ratio ) while ( $name, $height, $weight ) = $sth->fetchrow_array() );
Now, in regard to your swap example, the behavior there is currently undefined in that you're creating circular references with lazy evaluation (Just like you can do in Excel). I expect this to flag a runtime error , possibly a compile-time error. But until we have Perl 6 in our hands, we won't know for sure.
Update as pointed out below, I got myself confused with the := operator and perl laziness.
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
It's not what you know, but knowing how to find it if you don't know that's important
In reply to Re: Comprehending Binary :=
by Masem
in thread Comprehending Binary :=
by swiftone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |