Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsinking sunk calls via CALL-ME

Tags:

raku

While trying to come up with an example of maps in sunk context, I bumped into this code:

my $a = -> { 42 };
my $b = -> { "foo" };

$a;
$a();

($a,$b).map: { $_ };

The first call to $a by itself returns:

WARNINGS for /home/jmerelo/Code/raku/my-raku-examples/sunk-map.p6:
Useless use of $a in sink context (line 6)

However, putting .() or () behind, or using them in (what I though it was) sink context in a map didn't result in any warning. Probably it's not sink context, but I would like to know why.

like image 306
jjmerelo Avatar asked Feb 12 '20 07:02

jjmerelo


1 Answers

$a;
$a();
($a,$b).foo ...

The first call to $a by itself

That's not a "call". That's just a mention of it aka "use". (Note: this, er, use of "use" has nothing to do with the keyword use in a use statement.)

WARNINGS for /home/jmerelo/Code/raku/my-raku-examples/sunk-map.p6: Useless use of $a in sink context (line 6)

Right. Just mentioning it like that is useless. You don't do anything with the value of $a (which has been assigned a function). You just drop it on the floor.

However, putting .() or () behind, or using them in (what I though it was) sink context in a map didn't result in any warning.

Right. Those cause .CALL-ME to be invoked on their left hand side. Those are understood to be potentially useful regardless of whether any value returned by the call is used by the code. So there's no warning despite being in sink context (though perhaps sink context is itself context dependent and at the compiler level they aren't even considered to be in sink context; I don't know).

cf my comment about a similar situation in perl.

like image 103
raiph Avatar answered Nov 10 '22 18:11

raiph