mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 14:49:18 +02:00
Allowing alist initializers for memoize cache.
This commit is contained in:
parent
badc6765f0
commit
0e7baa96e8
1 changed files with 16 additions and 8 deletions
|
@ -93,14 +93,22 @@
|
|||
(init-size init-size: 31)
|
||||
(limit size-limit: 1000)
|
||||
(compute-size compute-size: (lambda (k v) 1))
|
||||
(cache cache: (if limit
|
||||
(make-lru-cache 'equal: equal
|
||||
'hash: hash
|
||||
'init-size: init-size
|
||||
'size-limit: limit
|
||||
'compute-size: compute-size)
|
||||
(make-hash-table equal hash))))
|
||||
(make-memoizer proc arity cache)))
|
||||
(cache-init cache: '()))
|
||||
(let ((cache (cond ((lru-cache? cache-init)
|
||||
cache-init)
|
||||
(limit
|
||||
(make-lru-cache 'equal: equal
|
||||
'hash: hash
|
||||
'init-size: init-size
|
||||
'size-limit: limit
|
||||
'compute-size: compute-size))
|
||||
(else
|
||||
(make-hash-table equal hash)))))
|
||||
;; allow an alist initializer for the cache
|
||||
(if (pair? cache-init)
|
||||
(for-each (lambda (x) (lru-add! cache (car x) (cdr x)))
|
||||
cache-init))
|
||||
(make-memoizer proc arity cache))))
|
||||
|
||||
;;> Equivalent to memoize except that the procedure's first argument
|
||||
;;> must be a pathname. If the corresponding file has been modified
|
||||
|
|
Loading…
Add table
Reference in a new issue