mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-12 15:27:36 +02:00
Adding temporarily for testing
This commit is contained in:
parent
2b115c989d
commit
411347a556
1 changed files with 26 additions and 0 deletions
26
memo.scm
Normal file
26
memo.scm
Normal 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)
|
Loading…
Add table
Reference in a new issue