in reply to Re: Re (tilly) 2: Comprehending Binary :=
in thread Comprehending Binary :=

we're back to := just saving keystrokes

Hey! That's an important achievement. ;-)

But, of course, there are many other uses for binding too (some of which have already been mentioned in this thread). Here's another that hasn't been mentioned yet. Binding is particularly useful when you have lvalue subroutines/methods and you want to do something complex with the lvalue. Rather than repeatedly calling the subroutine/method:

while (<>) { $obj.threshold += $_ unless $obj.threshold > $min; }

you can just bind the lvalue once and use the bound variable instead:

my $thresh := $obj.threshold; while (<>) { $thresh += $_ unless $thresh > $min; }

Replies are listed 'Best First'.
(MeowChow) Re6: Comprehending Binary :=
by MeowChow (Vicar) on Oct 08, 2001 at 07:58 UTC
    Is this a use beyond simply saving keystrokes, or did I misunderestimate what you wrote?
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      No, we're not just saving keystrokes here. We're saving repeated calls to the lvalue method. And, even though method calls in Perl 6 will be faster, not doing any calls in the loop is still a real saving if the loop iterates many times.

      Damian

        So at what point does the lvalue method get called, once $thresh goes out of scope, or once the object is accessed, or at some other time?
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print