From 58949ddd80e2fd47e039ed96630852e49d7d93e9 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 4 Aug 2023 14:11:52 +0200 Subject: Start on memoize --- gn3-guile/web/webserver.scm | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gn3-guile/web/webserver.scm') diff --git a/gn3-guile/web/webserver.scm b/gn3-guile/web/webserver.scm index cddd9a5..7428640 100755 --- a/gn3-guile/web/webserver.scm +++ b/gn3-guile/web/webserver.scm @@ -17,6 +17,7 @@ ;; (ice-9 breakpoints) ;; (ice-9 source) (srfi srfi-1) + (srfi srfi-13) ; hash table for memoize (srfi srfi-26) (web http) (web client) @@ -25,6 +26,18 @@ (web uri) (fibers web server)) +(define (memoize function) + (let ((table (make-hash-table))) + (lambda args + (apply values (hash-ref table args + ;; If the entry isn't there, call the function. + (lambda () + (call-with-values + (lambda () (apply function args)) + (lambda results + (hash-set! table args results) + results)))))))) + (define get-version "2.0") -- cgit v1.2.3