From 72d448e384249103748ee83b587c45924e4bc44d Mon Sep 17 00:00:00 2001 From: sefidel Date: Thu, 10 Feb 2022 00:24:03 +0900 Subject: Initial commit --- fnl/nvrc/macro/thread.fnl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 fnl/nvrc/macro/thread.fnl (limited to 'fnl/nvrc/macro/thread.fnl') diff --git a/fnl/nvrc/macro/thread.fnl b/fnl/nvrc/macro/thread.fnl new file mode 100644 index 0000000..9060b04 --- /dev/null +++ b/fnl/nvrc/macro/thread.fnl @@ -0,0 +1,15 @@ +(local {: insert} table) + +(lambda as-> [[binding expr] ...] + "A threading macro where the first argument is the value binded to the + second argument, which must be a symbol. + This binding is valid for the whole body of the threading macro." + (assert-compile (sym? binding) "expected symbol for binding" binding) + `(let [,binding ,expr + ,(unpack (accumulate [exprs [] _ expr (ipairs [...])] + (doto exprs + (insert binding) + (insert expr))))] + ,binding)) + +{: as->} -- cgit 1.4.1