From 75b7335c740541e8c3ff5f234cc9d9686a7fee1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 21 Jul 2021 18:50:48 +0200 Subject: [PATCH] :art: Put memoize pragma inside function --- docs/Reference/Preprocessor.mdr | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 >>>; @``` -- 2.43.0