mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
Cut-over to Cyc-memoize
This commit is contained in:
parent
4632efc71d
commit
12b6131992
2 changed files with 22 additions and 22 deletions
42
memo.scm
42
memo.scm
|
@ -3,27 +3,27 @@
|
|||
(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)
|
||||
; (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)
|
||||
|
||||
; Original versions:
|
||||
(define (ack m n)
|
||||
|
|
|
@ -193,7 +193,7 @@
|
|||
(set-global! ,var ,rsym)
|
||||
,acc)))
|
||||
)
|
||||
`(memoize
|
||||
`(Cyc-memoize
|
||||
,(ast:make-lambda (list rsym) body)
|
||||
,new-var)))
|
||||
exp
|
||||
|
|
Loading…
Add table
Reference in a new issue