Again on the tail of this question, I'm trying to make a will
trait work, with this (golfed) code:
sub show-value( $a-var ) {
say "Value of {$a-var.^name} is ", $a-var.gist;
}
sub do-stuff () {
ENTER { say "Going in"; }
our $bar will enter { show-value($_) };
$bar = "baz";
LEAVE { say "Leaving"; }
}
do-stuff();
This simply prints "Going in". It (doesn't) work(s) in the same way if you do it on the global scope. Please note that this is an almost direct implementation of the documentation example.
You haven't noted your Rakudo version. It sounds like a bug introduced this year.
Running the same code using glot.io:
v2021.02.1
Going in
Value of Any is (Any)
Leaving
On 2021.07 I get:
Going in
Value of Any is (Any)
Leaving
A clearer example might be:
my $bar will enter { $_ = 42 }
say "bar = $bar"; # bar = 42
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With