💾 Archived View for idiomdrottning.org › schlemoize captured on 2024-05-10 at 11:29:07. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-04-19)

-=-=-=-=-=-=-

schlemoize

Just so I could cache some values.

(define zbd #f)

(define (get-stored key)
  ((or zbd
       (begin
         (set! zbd
               (call-table
                seed:
                (with-input-from-file "/home/sandra/.zbd.scm"
                  read-list)))
         zbd))
   key))

(define (store key . vals)
  (with-output-to-file "/home/sandra/.zbd.scm"
    (fn (write (cons key vals)))
    #:append)
  (apply values
         (if zbd
             (zbd key vals)
             vals)))

(define ((schlemoize func) key)
  (eif (get-stored key)
       (apply values it)
       (->>* (func key) (store key))))

Probably the slowest database in the world but I’m too exhausted to try to grok the docs of something like LMDB or TokyoCabinet.

I clear it out with cron.