From 411347a556411b15e9649bc2d0e0fb0ac5a01f01 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 29 Jan 2019 19:02:43 -0500 Subject: [PATCH] Adding temporarily for testing --- memo.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 memo.scm diff --git a/memo.scm b/memo.scm new file mode 100644 index 00000000..af3d45da --- /dev/null +++ b/memo.scm @@ -0,0 +1,26 @@ +;; Temporary test file, try with the ack function +(import (scheme base) + (srfi 69) + (scheme write)) + + (define (memoize function) + (let ((table (make-hash-table))) ;(make-equal?-map))) + (lambda args + (apply values + ;(map-get table + (hash-table-ref table + args + ;; If the entry isn't there, call the function. + (lambda () + (call-with-values + (lambda () (apply function args)) + (lambda results + ;(map-put! table args results) + (hash-table-set! table args results) + results)))))))) + +(define (fnc x y) (+ x y)) +(define mfnc (memoize fnc)) + +(write (mfnc 1 1)) (newline) +(write (mfnc 1 1)) (newline)