diff options
author | sefidel <contact@sefidel.net> | 2022-02-10 00:24:03 +0900 |
---|---|---|
committer | sefidel <contact@sefidel.net> | 2022-02-10 00:24:03 +0900 |
commit | 72d448e384249103748ee83b587c45924e4bc44d (patch) | |
tree | 2aa05a6aaf8c7aa37a8c278fd2fede6e62ff2218 /fnl/nvrc/macro/toolkit.fnl | |
download | nvimrc-72d448e384249103748ee83b587c45924e4bc44d.tar.gz nvimrc-72d448e384249103748ee83b587c45924e4bc44d.zip |
Initial commit
Diffstat (limited to 'fnl/nvrc/macro/toolkit.fnl')
-rw-r--r-- | fnl/nvrc/macro/toolkit.fnl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/fnl/nvrc/macro/toolkit.fnl b/fnl/nvrc/macro/toolkit.fnl new file mode 100644 index 0000000..8a2bc50 --- /dev/null +++ b/fnl/nvrc/macro/toolkit.fnl @@ -0,0 +1,39 @@ +(local {: format} string) + +(fn ->str [x] + (tostring x)) + +(fn head [xs] + (. xs 1)) + +(fn fn? [x] + "Returns whether the parameter(s) is a function. + A function is defined as any list with 'fn or 'hashfn as + their first element." + (and (list? x) (or (= `fn (head x)) (= `hashfn (head x))))) + +(lambda gensym-checksum [...] + "Generates a new symbol from the checksum of the object + passed as a parameter. + The parameter first is casted into a string using the + function `fennel.view`. + If only one parameter is passed to the function the return + value is the checksum as a symbol. + If two parameters are passed, the first one is considered + the prefix. + If three parameters are passed, the first one is considered + the prefix and the last one is considered the suffix. + This function depends on the md5 library and the fennel library." + (match [...] + [prefix object suffix] (let [{: view} (require :fennel) + {:sumhexa md5} (require :md5)] + (sym (.. prefix (md5 (view object)) suffix))) + [prefix object] (gensym-checksum prefix object "") + [object] (gensym-checksum "" object ""))) + +(lambda vlua [x] + "Return a symbol mapped to `v:lua.%s()`, where `%s` is the symbol." + (assert-compile (sym? x) "expected symbol for x" x) + (format "v:lua.%s()" (->str x))) + +{: fn? : gensym-checksum : vlua} |