Last active
August 29, 2015 14:12
-
-
Save daniel-j-h/06a92cd774555e2e7ad4 to your computer and use it in GitHub Desktop.
Hy: python+clojure (see: hylang.org)
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
#!/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