Basically, the := operator is a lazy assignment, which means that, in a conceptual manner, the calculation/operation is not really done until the result is absolutely needed as opposed to '=' and being done right then and there (from an implimentation standpoint, I would not be surprised to see that lazy evaluations are 'flattened' into the actual locations where needed.).

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:

while ( my ( $name, $height, $weight ) = $sth->fetchrow_array() ) { my $ratio = $height/$weight; send_to_html( $name, $ratio ); }
With lazy eval:
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() );
This may not seem as powerful now, but there's a lot of potental for it.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.