Created
August 17, 2010 05:10
-
-
Save deltam/528544 to your computer and use it in GitHub Desktop.
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
; 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