Course of Raku / Objects, I/O, and exceptions / Classes and objects / Subroutines vs methods / Exercises / Triple as a subroutine

Solution: Triple as a subroutine

Here is a possible solution to the task.

Code

sub triple($x) {
    $x * 3;
}

say triple(7);

🦋 You can find the source code in the file triple-sub.raku.

Output

21

Comments

  1. As a subroutine, triple is a standalone operation: it receives the value to work on as an argument.

  2. The companion exercise solves the same task as a method, so you can compare the two approaches.

Course navigation

Triple as a subroutine   |   Triple as a method