Skip to content

Instantly share code, notes, and snippets.

@daniel-j-h
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniel-j-h/06a92cd774555e2e7ad4 to your computer and use it in GitHub Desktop.
Save daniel-j-h/06a92cd774555e2e7ad4 to your computer and use it in GitHub Desktop.
Hy: python+clojure (see: hylang.org)
#!/usr/bin/env hy
(import [operator [eq]]
[itertools [chain count]]
[functools [partial reduce]])
(defn map-indexed [f coll]
(map f (count) coll))
(defn mapcat [f &rest colls]
(apply chain (apply (partial map f) colls)))
(defn contains? [v coll]
(some (partial eq v) coll))
(defmain [&rest args]
(let [[name (first args)]
[argv (rest args)]]
(->> argv
(map-indexed (fn [i v] (.format "{}: {}" i v)))
(.join "\n")
(print))))
;; => (list (take 5 (map-indexed * (count))))
;; [0, 1, 4, 9, 16]
;; => (list (mapcat (fn [x] (-> x reversed list)) [[3 2 1 0] [6 5 4] [9 8 7]]))
;; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
;; => (contains? 42 (count))
;; True
;; (env) $ hy core.hy hello world
;; 0: hello
;; 1: world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment