From the keyboard of Paul "LeoNerd" Evans [17.06.21,20:49]:
> On Thu, 17 Jun 2021 14:35:27 -0500
> David Nicol <davidnicol@gmail.com> wrote:
>
>> really? you've said "defer <CODEREF>" repeatedly
>
> I hope I haven't ever said that. I have mentioned `defer { BLOCK }`.
>
> Blocks aren't coderefs.
>
> E.g. consider the way that if(COND) { BLOCK } is not a coderef.
>
> It's verymuch not a coderef - `caller()` can't see it, it doesn't get
> its own `@_`, you can't `return` from it, etc...
Well, a BLOCK passed to a sub is very likely a CODEREF - at least inside
the subroutine:
sub foo (&) {
say $_[0];
$_[0]->();
}
foo { say "calling foo()" }
__END__
CODE(0x55b2e63b2440)
calling foo()
So, a flow control block attached to if, for, while etc is not a CODEREF,
but one passed to a function is, e.g. sort { $b <=> $a }, also with map
although slightly different:
$f = sub { $_ x 2 };
say for map $f->(), qw(a b c);
__END__
aa
bb
cc
And since "defer" is a function, it takes a coderef.
0--gg-
--
_($_=" "x(1<<5)."?\n".q?/)Oo. G?\ /
/\_?/(q /
---------------------------- \__(m.====?.(_("always off the crowd"))."?
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
> On Thu, 17 Jun 2021 14:35:27 -0500
> David Nicol <davidnicol@gmail.com> wrote:
>
>> really? you've said "defer <CODEREF>" repeatedly
>
> I hope I haven't ever said that. I have mentioned `defer { BLOCK }`.
>
> Blocks aren't coderefs.
>
> E.g. consider the way that if(COND) { BLOCK } is not a coderef.
>
> It's verymuch not a coderef - `caller()` can't see it, it doesn't get
> its own `@_`, you can't `return` from it, etc...
Well, a BLOCK passed to a sub is very likely a CODEREF - at least inside
the subroutine:
sub foo (&) {
say $_[0];
$_[0]->();
}
foo { say "calling foo()" }
__END__
CODE(0x55b2e63b2440)
calling foo()
So, a flow control block attached to if, for, while etc is not a CODEREF,
but one passed to a function is, e.g. sort { $b <=> $a }, also with map
although slightly different:
$f = sub { $_ x 2 };
say for map $f->(), qw(a b c);
__END__
aa
bb
cc
And since "defer" is a function, it takes a coderef.
0--gg-
--
_($_=" "x(1<<5)."?\n".q?/)Oo. G?\ /
/\_?/(q /
---------------------------- \__(m.====?.(_("always off the crowd"))."?
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}