* templates (both class and functions)
* easy concurrency/async
* [lambdas](Reference/Functions/Lambdas.html)
- * memoization
+ * [memoization](Reference/Preprocessor.md#Memoization)
* [variadic](Reference/Functions/Variadic.html) functions
# Gwion Preprocessor
+
+## Memoization
+
+You can use the `memoize` pragma to enable [memoization](wikipedia.org/wiki/Memoization) on functions:
+
+### normal version
+
+@``` fib_recurs.gw
+fun int recursive_fib(int n) {
+ if (n < 2)
+ return n;
+ else
+ return recursive_fib(n - 2) + recursive_fib(n - 1);
+}
+<<< 40 => recursive_fib >>>;
+@```
+
+### memoized version
+
+The syntax of the `memoize` pragma is as follow:
+``` cpp
+#pragma memoization <number of results to store>
+```
+
+See the memoized version of previous function:
+@``` fib_recurs_memoize.gw
+#pragma memoize 2
+fun int recursive_fib(int n) {
+ if (n < 2)
+ return n;
+ else
+ return recursive_fib(n - 2) + recursive_fib(n - 1);
+}
+<<< 40 => recursive_fib >>>;
+@```
+
+Under circomstance where memoization is applicable,
+such as this one, you can see a *huge* speed-up.
+
+@hide echo "normal: $(perf stat gwion fib_recurs.gw 2>&1 | grep elapsed)"
+@hide echo "memoized: $(perf stat gwion fib_recurs_memoize.gw 2>&1 | grep elapsed)"
+
+Memoization setting will be active until the end of file
+or until it is changed.
+Therefor, if you want to disable memoization for subsequent functions, use:
+``` cpp
+#pragma memoize 0
+```
+