in reply to RE (tilly) 1: Fly Subroutines on the Fly
in thread Fly Subroutines on the Fly
What do you mean by "Where closures rock is as a way to provide optional hooks when you compile a function without paying any run-time price if the hook was not included".
Could you provide an example of what you mean?
And why is eval being used here at all? Wouldn't the following be simpler, faster, and easier to maintain?
That's what I'd call a closure (well, the subroutines returned anyway, make_divide itself isn't one, but it's return values are).sub make_divide # "Half" is a lousy name for a curried divide { my $n = shift; if (Power_Of_Two($n)) { my $log = Log2($n); return sub { return $_[0] >> $log; }; } else { return sub { return int( $_[0] / $n ); }; } }
So, as I so often ask, what am I missing?
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: RE (tilly) 1: Fly Subroutines on the Fly
by chromatic (Archbishop) on Sep 19, 2000 at 07:09 UTC | |
RE (tilly) 3: Fly Subroutines on the Fly
by tilly (Archbishop) on Sep 19, 2000 at 15:23 UTC | |
by BlaisePascal (Monk) on Sep 19, 2000 at 22:29 UTC | |
by Adam (Vicar) on Sep 19, 2000 at 22:41 UTC | |
by merlyn (Sage) on Sep 19, 2000 at 22:32 UTC | |
by tilly (Archbishop) on Sep 19, 2000 at 23:05 UTC | |
RE: (3) (tilly) 1: Fly Subroutines on the Fly
by Adam (Vicar) on Sep 19, 2000 at 19:37 UTC | |
by tilly (Archbishop) on Sep 19, 2000 at 19:49 UTC |