Skip to content

Instantly share code, notes, and snippets.

@deltam
Created August 17, 2010 05:10
Show Gist options
  • Save deltam/528544 to your computer and use it in GitHub Desktop.
Save deltam/528544 to your computer and use it in GitHub Desktop.
; Googleグループ clojure-ja
; 質問: 関数型プログラミングでいうZip関数をClojureではどう書く?
; <http://groups.google.com/group/clojure-ja/browse_thread/thread/98cc4e3b7bcb4a28#>
; それぞれREPL実行結果まとめ
(def a [1 2 3 4])
(def b [5 6 7 8])
; はやみずさんのアイデア
(map (fn [x y] (vector x y)) a b)
;([1 5] [2 6] [3 7] [4 8])
; 武藤さんのアイデア
(defn fasten [arg & args]
(apply map (concat [list arg] args)))
(fasten a b)
;((1 5) (2 6) (3 7) (4 8))
; 登尾さんのアイデア
(doseq [[x y] (zipmap a b)] (prn x y))
;4 8
;3 7
;2 6
;1 5
;nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment