aboutsummaryrefslogtreecommitdiff
path: root/gn3-guile/web/webserver.scm
diff options
context:
space:
mode:
authorPjotr Prins2023-08-04 14:11:52 +0200
committerPjotr Prins2023-08-04 14:11:52 +0200
commit58949ddd80e2fd47e039ed96630852e49d7d93e9 (patch)
tree44a78a6092249f4f184fef1a1c6412f263857542 /gn3-guile/web/webserver.scm
parent1c0b72030ce3fdc67bba3fd2d18864dd1cfd9bb0 (diff)
downloadgenenetwork3-58949ddd80e2fd47e039ed96630852e49d7d93e9.tar.gz
Start on memoize
Diffstat (limited to 'gn3-guile/web/webserver.scm')
-rwxr-xr-xgn3-guile/web/webserver.scm13
1 files changed, 13 insertions, 0 deletions
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")