in reply to Comprehending Binary :=
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: Comprehending Binary :=
by tilly (Archbishop) on Oct 06, 2001 at 16:21 UTC | |
by swiftone (Curate) on Oct 06, 2001 at 21:50 UTC | |
by TheDamian (Vicar) on Oct 08, 2001 at 07:37 UTC | |
by TheDamian (Vicar) on Oct 08, 2001 at 07:24 UTC | |
by MeowChow (Vicar) on Oct 08, 2001 at 07:58 UTC | |
by TheDamian (Vicar) on Oct 08, 2001 at 08:06 UTC | |
| |
by tilly (Archbishop) on Oct 07, 2001 at 22:14 UTC | |
|
Re: Re: Comprehending Binary :=
by demerphq (Chancellor) on Oct 06, 2001 at 16:19 UTC | |
|
Re: Re: Comprehending Binary :=
by raptor (Sexton) on Oct 06, 2001 at 20:43 UTC |