aboutsummaryrefslogtreecommitdiff
path: root/web/webserver.scm
diff options
context:
space:
mode:
Diffstat (limited to 'web/webserver.scm')
-rwxr-xr-xweb/webserver.scm37
1 files changed, 7 insertions, 30 deletions
diff --git a/web/webserver.scm b/web/webserver.scm
index ce754d8..910024f 100755
--- a/web/webserver.scm
+++ b/web/webserver.scm
@@ -25,31 +25,8 @@
(web request)
(web response)
(web uri)
- (fibers web server))
-
-;; basically lifted from https://lispdreams.wordpress.com/2016/04/08/lisp-memoization-techniques/
-
-(define (memoize f)
- "Simple memoize just uses alists at this point and does not expire"
- (let ((result-table '()))
- (lambda (. args)
- (let ((cache-value (assoc args (pk result-table))))
- (if (pk cache-value)
- (cdr cache-value)
- (let ((result (apply f args)))
- (set! result-table
- (alist-cons args result result-table)) result))))))
-
-(define (memoize2 f)
- "Simple memoize functions that returns values pair and uses alists at this point and does not expire"
- (let ((result-table '()))
- (lambda (. args)
- (let ((c (assoc args (pk result-table))))
- (if (pk c)
- (values (car (cdr c)) (car (cdr (cdr c))))
- (let-values (((r1 r2) (apply f args)))
- (set! result-table
- (alist-cons args (list r1 r2) result-table)) (values r1 r2)))))))
+ (fibers web server)
+ (gn cache memoize))
(define get-version
"2.0")
@@ -107,7 +84,7 @@
("prefix" . ,(prefix))
("links". (("species" . ,(mk-meta "species"))))))
-(define info-meta `(
+(define info-meta `(
("doc" . ,(mk-html "info"))
("API" .
((,(mk-url "species")."Get a list of all species")
@@ -119,7 +96,7 @@
"Execute raw SPARQL query returning response as a UTF8 string"
(bytevector->string (receive (response-status response-body)
(http-request (string-append endpoint-url "?default-graph-uri=&query=" (uri-encode query) "&format=application%2Fsparql-results%2Bjson"))
-
+
response-body) "UTF-8"))
(define (sparql-tsv endpoint-url query)
@@ -201,7 +178,7 @@ SELECT DISTINCT * where { wd:Q158695 wdt:P225 ?o . } limit 10
"
(sparql-tsv (wd-sparql-endpoint-url) (string-append "
-SELECT DISTINCT ?taxon ?ncbi ?descr where {
+SELECT DISTINCT ?taxon ?ncbi ?descr where {
wd:" species " " (wdt-taxon-name) " ?taxon ;
wdt:P685 ?ncbi ;
schema:description ?descr .
@@ -263,7 +240,7 @@ SELECT ?species ?p ?o WHERE {
(define (get-rows names results)
"Format results as a list of values ordered by names"
(map (lambda (row) (get-values names row)) (array->list results)))
-
+
;; from the triples first harvest the species URIs, followed by creating records of information
(define (compile-species recs rows)
@@ -406,7 +383,7 @@ SELECT ?species ?p ?o WHERE {
;; (display "ThthxST" port)
(format port "~a" "foo")
)))
-
+
(define (controller request body)
(match-lambda
(('GET)