Last active
December 28, 2015 05:59
-
-
Save theanalyst/7453586 to your computer and use it in GitHub Desktop.
An attempt at writing some sequence utils in hy (heavily inspired by dash.el)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro inc! [var] | |
`(setv ~var (inc ~var))) | |
(defmacro --dotimes [n &rest body] | |
"Anaphoric form of dotimes; allows `it' to be used in the body for | |
eg. (--dotimes 10 (print it))" | |
`(let [[it 0]] | |
(while (< it ~n) | |
~@body | |
(inc! it)))) | |
(defmacro -dotimes [n &rest body] | |
`(foreach [i (range ~n)] ~@body)) | |
(defmacro -concat [item &rest coll] | |
"a buggy concat, works for strings and collections normally, will | |
break when you try something fancy in arguments like a function | |
that returns a list" | |
(if (all (map iterable? coll)) `(+ ~item ~@coll) | |
(raise (macro-error coll "invalid args..must be collections")))) | |
(defn mapcat [f &rest colls] | |
(let [[res []]] | |
(for [coll colls it coll] | |
(.extend res (f it))) | |
res)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment