Skip to content

Instantly share code, notes, and snippets.

@lucs
Created November 3, 2023 20:33
Show Gist options
  • Save lucs/1f05e1542874116616a015cf6e798112 to your computer and use it in GitHub Desktop.
Save lucs/1f05e1542874116616a015cf6e798112 to your computer and use it in GitHub Desktop.
How can I make this work.
# --------------------------------------------------------------------
# do-block.raku
my %bazes;
class Baz {
has $.id;
has $.block;
method make (
$id,
$block,
) {
%bazes{$id} = self.bless:
:$id,
:$block,
;
}
method do-block (*@a) {
note "join: ", @a.join: '-';
note "WHAT: ", $.block.WHAT;
note "raku: ", $.block.raku;
note "sign: ", $.block.signature;
say $.block(| @a);
note "This doesn't get printed, so previous line failed, eh.";
}
}
Baz.make: 'b1', -> $x, $y { $x + $y };
Baz.make: 'b2', -> $x, $y { $x * $y };
note "Expecting «4\\n» from「\%bazes<b1>.do-block(1, 3)」.";
%bazes<b1>.do-block(1, 3);
note "Expecting «8\\n» from「\%bazes<b2>.do-block(2, 4)」.";
%bazes<b2>.do-block(2, 4);
# --------------------------------------------------------------------
=finish
The code contains statements I used for debugging.
Prints:
Expecting «4\n» from「%bazes<b1>.do-block(1, 3)」.
join: 1-3
WHAT: (Block)
raku: -> $x, $y { #`(Block|35203328) ... }
sign: ($x, $y)
Too many positionals passed; expected 1 argument but got 3
in method block at do-block.raku line 6
in method do-block at do-block.raku line 25
in block <unit> at do-block.raku line 35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment