David Storrs writes:
> On Wed, Jan 14, 2004 at 11:57:05AM +0000, Richard Nuttall wrote:
> 
> > How about
> > 
> > $test = sub
> > {
> >     if ( some_expensive_lookup_function() >= $MAX_RECORDS )
> > 
> >        mark_that_we_have_reached_max_records();       
> > 
> >        $test = sub{};
> > };
> > 
> > Then call &$test() as needed;
> 
> 
> Neat.  I wouldn't have thought of that; thank you.

Let's not mention that that has way more overhead than a
short-circuiting test, but I guess "the idea's the important thing".

Slight correction here, 

    &$test()

will not call that sub.  Both of:

    $test()
    $test.()

Will, and I think

    &$test.()

Will, but &$test() just refers to the sub object itself.

Which brings up a question:  Can you have a sub reference to a multi?
That is to say, one reference referring to a multiply-dispatched name.
For example:

    multi sub typrint(Int $x) { print "Int $x" }
    multi sub typrint(Str $x) { print "Str $x" }

    my $ref = &typrint;

    $ref.(99);        # Int 99
    $ref.("Hello");   # Str Hello

?

Luke

Luke

> --Dks

Reply via email to