You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I notice the Raku Guide has a section on functional programming but makes no mention of recursion. In functional programming recursion is favored over loops. So, this strikes me as a significant omission to the section.
Andrew Shitov's has a blog post Computing Factorials Using Raku that gives an excellent and highly readable recursion example in Raku. You might want to use a similar example. From his post:
unit subMAIN($n);
subfactorial($n) {
return1if$n<2;
return$n* factorial($n-1);
}
say factorial($n);
As you can see the code uses a postfix if on a return statement. It's a very readable and idiomatic way to create a recursive function. It's also worth mentioning that, according to the official Raku documentation, if can be used this way but attempting to do the same thing with else or elsif results in a syntax error. This is also probably worth mentioning.
The text was updated successfully, but these errors were encountered:
I notice the Raku Guide has a section on functional programming but makes no mention of recursion. In functional programming recursion is favored over loops. So, this strikes me as a significant omission to the section.
Andrew Shitov's has a blog post Computing Factorials Using Raku that gives an excellent and highly readable recursion example in Raku. You might want to use a similar example. From his post:
As you can see the code uses a postfix if on a return statement. It's a very readable and idiomatic way to create a recursive function. It's also worth mentioning that, according to the official Raku documentation, if can be used this way but attempting to do the same thing with else or elsif results in a syntax error. This is also probably worth mentioning.
The text was updated successfully, but these errors were encountered: