--- Dave Whipp <[EMAIL PROTECTED]> wrote:
> Dulcimer wrote:
> >>sub slow_fn {
> >>   my $tick = Timer.new(60, { print "..." });
> >>   return slow_fn_imp @_;
> >>}
> >>
> >>Now if I could just get the compiler to not complain about that
> >>unused variable...
> > 
> > 
> > Maybe I'm being dense....
> > Why not just
> >  sub slow_fn {
> >    Timer.new(1, { print "." });
> >    return slow_fn_imp @_;
> >  }

Geez. I read my response this morning, which I wrote just before going
to bed, and realized that I must've been dead on my feet.

> The problem is that I want the timer to last for the duration of the 
> slow_fn_imp. If I don't assign it to a variable, then it may be GCed
> at any time.

I was making several assumptions which don't hold, apparently, such as
that the underlying Timer would iterate until stopped. Not an ideal
default, lol.... I thopught the point was to have the function print
dots repeatedly, tho?

> I've just realised, however, that I'm relying on it being destroyed
> on leaving the scope. I'm not sure that the GC guarentees that.
> I might need
> 
>    sub slow_fn {
>      my $timer is last { .stop } = Timer.new(60, { print "." });
>      return slow_fn_imp @_;
>    }
> 
> but that's starting to get cluttered again.

I don't really consider that "clutter". It's clear and to the point,
and Does What You Want. How about 

  sub slow_fn {
    my $timer is last { .stop } = 
       new Timer secs => 1, reset => 1, code => {print "."};
    return slow_fn_imp @_;
  }

so that the timer goes off after a second, prints a dot, and resets
itself to go off again after another second? And I still like the idea
of an expanding temporal window between dots:

  sub slow_fn {
    my $pause = 1;
    my $timer is last { .stop } = new Timer secs => $pause++,
                                           reset => {$pause++},
                                            code => {print "."};
    return slow_fn_imp @_;
  }

As a sidenote, although it would actually reduce readability here, I'm
still trying to wrap my brain thoroughly around the new dynamics of $_.
Would this work correctly maybe?

  sub slow_fn {
    my $timer is last { .stop } = new Timer secs => $_=1,
                                           reset => {$_++},
                                            code => {print "."};
    return slow_fn_imp @_;
  }

Isn't that $_ proprietary to slow_fn such that it *would* work?

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

Reply via email to