in reply to Re: Tkx after coderef problem
in thread Tkx after coderef problem

>>And i suspect that the [] notation in the Tkx::after call is doing the same thing i did with the sub {}, creating a one use anonymous subroutine reference.

no it doesnt create an anonymous sub it doesnt need to

Replies are listed 'Best First'.
Re^3: Tkx after coderef problem
by huck (Prior) on Jun 03, 2018 at 18:13 UTC

    Sorry, yes it does. Found it!

    https://github.com/gisle/tcl.pm/blob/master/Tcl.pm lines 502-518

    elsif ($ref eq 'ARRAY' && ref($arg->[0]) eq 'CODE') { # We have been passed something like [\&subroutine, $arg1, ...] # Create a proc in Tcl that invokes this subroutine with args my $events; # Look for Tcl::Ev objects as the first arg - these must be # passed through for Tcl to evaluate. Used primarily for %-subs # This could check for any arg ref being Tcl::Ev obj, but it # currently doesn't. if ($#$arg >= 1 && ref($arg->[1]) eq 'Tcl::Ev') { $events = splice(@$arg, 1, 1); } $args[$argcnt] = $interp->create_tcl_sub(sub { $arg->[0]->(@_, @$arg[1..$#$arg]); }, $events, undef, $current_r); push @codes, $anon_refs{$current_r}; }
    Notice how lines 514-516 create a **perl** anon-sub

    Sorry, better luck next time!

Re^3: Tkx after coderef problem
by huck (Prior) on Jun 02, 2018 at 22:04 UTC

    "no it doesnt create an anonymous sub it doesnt need to

    If you are so sure of that then prove it, show me a link to the arrayref processing of Tkx:after calls, or tell me where to look for the code. Till then my thought that processing of a arrayref in the callback position creates a single use anon-coderef still holds as it explains why that call method works, like the the sub{...} method does, but the static coderef fails. (well at least on unix).

    There is deep autoload magic going on in Tkx that i still dont understand and i have yet to find out where the parameter munging actually takes place to move across the perl<->Tk/Tcl boundary. Ive even tried to look for it.

      Not going to prove anythung or fix typos. It doesnt need to create a subrkutine to be able to call a subroutine and pass arguments to it.Why would it . calling a subroutine is identical no matter a who creates it.