diff options
Diffstat (limited to 'dot_config/nvim/fnl/toast/macros.fnl')
| -rw-r--r-- | dot_config/nvim/fnl/toast/macros.fnl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/dot_config/nvim/fnl/toast/macros.fnl b/dot_config/nvim/fnl/toast/macros.fnl new file mode 100644 index 0000000..bb4375b --- /dev/null +++ b/dot_config/nvim/fnl/toast/macros.fnl @@ -0,0 +1,29 @@ +;; [nfnl-macro] + +(local {: inc + : drop + : group} (require :toast.core)) +(local {: from-pairs + : insert} (require :toast.table)) + +(fn tbl [...] + "Generate a mixed table. + The format is (tbl 1 2 3 & :a :b) to produce {1; 2; 3; a = 'b'}. + This macro simply expands to the correct data during compile-time." + (let [args [...] + pre (accumulate [out [] + _ v (ipairs args) + &until (= v '&)] + (insert out v)) + post (drop (inc (length pre)) args)] + (from-pairs (group 2 post) pre))) + +(fn recc [reqspec key ...] + "A common lua pattern is `require 'something'.call(arg1, arg2)`. + The fennel equivalent is ((require :something).call arg1 arg2) + This macro makes it easier to do this elegantly. + The equivalent call is (recc :something :call arg1 arg2)" + `((. (require ,reqspec) ,key) ,...)) + +{: tbl + : recc} |
