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
21Comments
As a subroutine,
tripleis a standalone operation: it receives the value to work on as an argument.The companion exercise solves the same task as a method, so you can compare the two approaches.