open Pp;; #load "interpret.cmo";; open Interpret;; let memo_fib = let fib = { arguments = ["n", Integer]; result = Some Integer; local_vars = []; body = If (Bin (Le, Get "n", Int 1), Set ("fib", Int 1), Set ("fib", (Bin (Plus, Geti (Get "t", Bin (Minus, Get "n", Int 1)), Geti (Get "t", Bin (Minus, Get "n", Int 2)))) )) } in { global_vars = ["t", Array Integer; "i", Integer]; definitions = ["fib", fib]; main = Sequence [ Set ("t", Alloc (Int 100, Integer)); Set ("i", Int 0); While (Bin (Le, Get "i", Int 30), Sequence [ Seti (Get "t", Get "i", Function_call ("fib", [Get "i"])); Set ("i", Bin (Plus, Get "i", Int 1)); ] ); Writeln_int (Geti (Get "t", Int 23)); ] } ;; eval memo_fib;;