Adding temporarily for testing

This commit is contained in:
Justin Ethier 2019-01-29 19:02:43 -05:00
parent 2b115c989d
commit 411347a556

26
memo.scm Normal file
View file

@ -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)