Tutorial by Examples: cursive

The code below calculates the value of PI using a recursive approach. Modify the MAX_PARALLEL_RECURSIVE_LEVEL value to determine at which recursion depth stop creating tasks. With this approach to create parallelism out of recursive applications: the more tasks you create, the more parallel tasks cr...
Variable declaration @buttonColor: #FF0000; /* Now you can use @buttonColor variable with css Functions. */ .product.into.detailed { additional-attributes{ .lib-table-button( background-color: @buttonColor; ); } } Here function lib-tabgle-button used v...
Fibonacci numbers are used as a very common example for teaching recursion. fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2)
If you try and create a recursive enum in Rust without using Box, you will get a compile time error saying that the enum can't be sized. // This gives an error! enum List { Nil, Cons(i32, List) } In order for the enum to have a defined size, the recursively contained value must be in...
One time definition of a generic base class with recursive type specifier. Each node has one parent and multiple children. /// <summary> /// Generic base class for a tree structure /// </summary> /// <typeparam name="T">The node type of the tree</typeparam> pub...
Using the previous example of calculating the factorial of an integer, put in the hash table all values of factorial calculated inside the recursion, that do not appear in the table. As in the article about memoization, we declare a function f that accepts a function parameter fact and a integer pa...
Recursive mutex allows the same thread to recursively lock a resource - up to an unspecified limit. There are very few real-word justifications for this. Certain complex implementations might need to call an overloaded copy of a function without releasing the lock. std::atomic_int temp{0}; ...
You can define a function to be recursive with the rec keyword, so it can call itself. # let rec fact n = match n with | 0 -> 1 | n -> n * fact (n - 1);; val fact : int -> int = <fun> # fact 0;; - : int = 1 # fact 4;; - : int = 24 You can also define mutually re...
function sum(numbers) { var total = 0; for (var i = numbers.length - 1; i >= 0; i--) { total += numbers[i]; } return total; } It's a procedural code with mutations (over total).
function sum(numbers) { if(numbers.length == 0) { return 0; } return numbers[0] + sum(numbers.slice(1)); } this is the recursive version. there's no mutation, but we are making a call stack as below which uses extra memory. sum([10, 5, 6, 7]);      10 + sum([5, 6, 7]); ...
function sum(numbers) { return tail_sum(numbers, 0); } function tail_sum(numbers, acc) { if(numbers.length == 0) { return acc; } return tail_sum(numbers.slice(1), acc + numbers[0]); } in the tail recursive version, function return value does not need to wait till...

Page 3 of 3