comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de>
Subject: Re: Implementing Memorize
Date: Thu, 23 Oct 2003 00:25:59 +0000 (UTC)
Date: 2003-10-23T00:25:59+00:00	[thread overview]
Message-ID: <bn776n$n7e$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: slrnbpch9n.oa.lutz@taranis.iks-jena.de

Lutz Donnerhacke <lutz@iks-jena.de> wrote:
: In order to implement a generic memorize, I tried the following
:  (see <slrnbpajhj.ns.lutz@taranis.iks-jena.de> for the context)

To mention some more context, this has come up in a language war
in de.comp.lang.misc where someone presented:

;;;; -*- Mode: Lisp; Syntax: Common-Lisp -*-
;;;; Code from Paradigms of AI Programming
;;;; Copyright (c) 1991 Peter Norvig
;;; ==============================

;;;; The Memoization facility:

(defun memo (fn &key (key #'first) (test #'eql) name)
  "Return a memo-function of fn."
  (let ((table (make-hash-table :test test)))
    (setf (get name :memo) table)
    #'(lambda (&rest args)
        (let ((k (funcall key args)))
          (multiple-value-bind (val found-p)
              (gethash k table)
            (if found-p val
                (setf (gethash k table) (apply fn args))))))))

(defun memoize (fn-name &key (key #'first) (test #'eql))
  "Replace fn-name's global definition with a memoized version."
  (clear-memoize fn-name)
  (setf (symbol-function fn-name)
        (memo (symbol-function fn-name)
              :name fn-name :key key :test test)))




  parent reply	other threads:[~2003-10-23  0:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-22  8:52 Implementing Memorize Lutz Donnerhacke
2003-10-22 15:00 ` Frank J. Lhota
2003-10-22 17:03 ` tmoran
2003-10-23  0:25 ` Georg Bauhaus [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-10-22  9:28 christoph.grein
2003-10-22 10:32 ` Lutz Donnerhacke
2003-10-22 10:48   ` Marius Amado Alves
2003-10-22 11:07     ` Lutz Donnerhacke
2003-10-22 11:33       ` Lutz Donnerhacke
2003-10-22 11:56         ` Lutz Donnerhacke
2003-10-22 12:29         ` Marius Amado Alves
2003-10-22 12:52           ` Lutz Donnerhacke
2003-10-22 13:42             ` Marius Amado Alves
2003-10-22 12:08       ` Dmitry A. Kazakov
2003-10-22 12:10         ` Lutz Donnerhacke
2003-10-22 15:23           ` Dmitry A. Kazakov
2003-10-22 19:41             ` Lutz Donnerhacke
2003-10-23 14:36               ` Dmitry A. Kazakov
2003-10-22 19:29       ` Robert I. Eachus
2003-10-22 19:44         ` Lutz Donnerhacke
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox