114 val start_acc = coins.filter(_ > 0).map(List(_)) |
114 val start_acc = coins.filter(_ > 0).map(List(_)) |
115 searchT(11, junk_coins, start_acc) |
115 searchT(11, junk_coins, start_acc) |
116 searchT(111, junk_coins, start_acc) |
116 searchT(111, junk_coins, start_acc) |
117 searchT(111111, junk_coins, start_acc) |
117 searchT(111111, junk_coins, start_acc) |
118 |
118 |
119 // moral: whenever a recursive function is resource-critical |
119 // Moral: Whenever a recursive function is resource-critical |
120 // (i.e. works on large recursion depth), then you need to |
120 // (i.e. works with large recursion depths), then you need to |
121 // write it in tail-recursive fashion |
121 // write it in tail-recursive fashion. |
|
122 // |
|
123 // Unfortuantely, the Scala is because of current limitations in |
|
124 // the JVM not as clever as other functional languages. It can |
|
125 // only optimise "self-tail calls". This excludes the cases of |
|
126 // multiple functions making tail calls to each other. Well, |
|
127 // nothing is perfect. |
|
128 |
|
129 |
122 |
130 |
123 |
131 |
124 // Polymorphic Types |
132 // Polymorphic Types |
125 //=================== |
133 //=================== |
126 |
134 |