A Clojure library that allows you to easily save and restore values to and from file, intended to be used as part of a REPL-based development workflow.
There are two main uses:
For a Leiningen project, use the following dependency:
[com.nomistech/slurp-or-evaluate "0.1.3"]
Add the following to your ns
declaration:
(:require [com.nomistech.slurp-or-evaluate :refer :all])
Use as follows:
(def-expensive foo ...my-expensive-computation...)
This is the same as def
, except:
def-expensive
has a saved value, it will use that instead of evaluating
...my-expensive-computation...
.def-expensive
does not have a saved value, it will save the result of
evaluating ...my-expensive-computation...
to file for future use.You can also have a doc string as follows:
(def-expensive foo "my doc string" ...my-expensive-computation...)
slurp-or-evaluate stores data in the directory _slurp-or-evaluate-store/
.
You may wish to exclude that directory from version control
(e.g. add it to your .gitignore
file).
The name of the var being defined must be a valid filename on
your system, because
slurp-or-evaluate uses the name of the var as the name
of the file in which to store the saved value (within the
_slurp-or-evaluate-store/
directory).
To remove slurp-or-evaluate's saved value for a var, you can either remove
its file from the _slurp-or-evaluate-store/
directory or you can use
def-expensive-replacing
to force an update.
A call of def-expensive-replacing
would probably only exist temporarily
— the idea is that you would change a call of def-expensive
to a call
of def-expensive-replacing
, evaluate it, and then change it back.
You can change where slurp-or-evaluate stores data with:
(alter-var-root #'slurp-or-evaluate-store-dir (constantly "my-store-dir"))
Copyright © 2016 Simon Katz
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close