(dolist (var init-form result) S式 ... )
dolist は名前が示すように、リストに関係があります。最初に init-form を評価します。このとき、評価結果はリストでなければいけません。リスト以外の場合はエラーとなります。dolist は、このリストの要素を順番に変数 var に代入して S 式を評価します。リストの要素がなくなったら result を評価し、その値が dolist の返り値になります。次の例を見てください。
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
(defn mapmap | |
"Return a new map, mapping keys to (keyfn key) and mapping values to | |
(valfn val)" | |
([valfn map] | |
(mapmap identity valfn map)) | |
([keyfn valfn map] | |
(persistent! (reduce | |
(fn [c [k v]] (assoc! c (keyfn k) (valfn v))) | |
(transient {}) | |
map)))) |
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
(defadvice paredit-newline (around eval-print-last-sexp activate) | |
(if (eq major-mode 'lisp-interaction-mode) | |
(eval-print-last-sexp) | |
(paredit-newline))) |
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
(defn one [] 1) | |
(defn div [v1 v2] | |
(float (/ v1 v2))) | |
(defparallelagg count | |
:init-var #'one | |
:combine-var #'+) | |
(defparallelagg sum-parallel |
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
; A REPL-based, annotated Seesaw tutorial | |
; Please visit https://github.com/daveray/seesaw for more info | |
; | |
; This is a very basic intro to Seesaw, a Clojure UI toolkit. It covers | |
; Seesaw's basic features and philosophy, but only scratches the surface | |
; of what's available. It only assumes knowledge of Clojure. No Swing or | |
; Java experience is needed. | |
; | |
; This material was first presented in a talk at @CraftsmanGuild in | |
; Ann Arbor, MI. |
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 defworld [name bindings & body] | |
`(defn ~name ~bindings | |
(fn [~'world] | |
(println ~'world) | |
~@body))) | |
(defmacro with-world [& body] | |
`(domonad state-m | |
~@body)) |
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 with-open-zipfile | |
[bindings & body] | |
(let [bindings# (->> bindings | |
(mapncat 2 (fn [v f] | |
`(~v (java.util.zip.ZipFile. ~f)))) | |
(into []))] | |
`(with-open ~bindings# ~@body))) | |
;; example |
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
(ns ident.viterbi | |
(:use [clojure.pprint])) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Example | |
;; (def initpr (to-array [0.6 0.4])) | |
;; (def transpr (to-array-2d [[0.7 0.3][0.4 0.6]])) | |
;; (def emisspr (to-array-2d [[0.1 0.4 0.5][0.6 0.3 0.1]])) | |
;; (def hmm (make-hmm {:states ["rainy" "sunny"] :obs ["walk" "shop" "clean"] :init-probs initpr :emission-probs emisspr :state-transitions transpr})) | |
;; optimal state sequence and probability of sequence |
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
(use 'cascalog.playground) (bootstrap) | |
(require '[clojure.set :as set]) | |
(require '[cascalog.vars :as v]) | |
(defn all-syms [form] | |
(if (coll? form) | |
(reduce (fn [curr elem] (set/union curr (all-syms elem))) | |
#{} | |
form) |
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
; | |
; STMの挙動を観察する | |
; スレッドを作るマクロ | |
; http://code.google.com/p/javaee-study/source/browse/trunk/clojure-concurrency/concurrency.clj?r=5 | |
(import '(java.lang Thread)) | |
(defmacro with-new-thread [& body] | |
`(.start (Thread. (fn [] ~@body)))) | |
; 指定された値がTrueになるまでブロックするチェックポイント |
OlderNewer