1
;; memoize.jl -- create caching-enabled functions
2
;; Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
4
;; $Id: memoize.jl,v 1.5 2000/07/23 22:24:33 john Exp $
6
;; This file is part of librep.
8
;; librep is free software; you can redistribute it and/or modify it
9
;; under the terms of the GNU General Public License as published by
10
;; the Free Software Foundation; either version 2, or (at your option)
13
;; librep is distributed in the hope that it will be useful, but
14
;; WITHOUT ANY WARRANTY; without even the implied warranty of
15
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
;; GNU General Public License for more details.
18
;; You should have received a copy of the GNU General Public License
19
;; along with librep; see the file COPYING. If not, write to
20
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
(define-structure rep.util.memoize
24
(export memoize memoize-function)
29
(define-structure-alias memoize rep.util.memoize)
32
"Create and return a caching version of the function F. F may not be
33
an autoload definition."
36
(error "can only memoize functions: %s" f))
38
(let ((cache (make-table equal-hash equal)))
41
(or (table-ref cache args)
42
(table-set cache args (apply f args))))))
44
;; backwards compatibility
45
(define memoize-function memoize))