From: Jérémie Astor Date: Wed, 21 Jul 2021 16:50:48 +0000 (+0200) Subject: :art: Put memoize pragma inside function X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=75b7335c740541e8c3ff5f234cc9d9686a7fee1c;p=gwion.git :art: Put memoize pragma inside function --- diff --git a/docs/Reference/Preprocessor.mdr b/docs/Reference/Preprocessor.mdr index 94317385..01b2f34f 100644 --- a/docs/Reference/Preprocessor.mdr +++ b/docs/Reference/Preprocessor.mdr @@ -10,8 +10,7 @@ You can use the `memoize` pragma to enable [memoization](https://wikipedia.org/w fun int recursive_fib(int n) { if (n < 2) return n; - else - return recursive_fib(n - 2) + recursive_fib(n - 1); + return recursive_fib(n - 2) + recursive_fib(n - 1); } <<< 40 => recursive_fib >>>; @``` @@ -25,12 +24,11 @@ The syntax of the `memoize` pragma is as follow: See the memoized version of previous function: @``` fib_recurs_memoize.gw -#pragma memoize 2 fun int recursive_fib(int n) { +#pragma memoize 2 if (n < 2) return n; - else - return recursive_fib(n - 2) + recursive_fib(n - 1); + return recursive_fib(n - 2) + recursive_fib(n - 1); } <<< 40 => recursive_fib >>>; @```