Back
repeat (clj)
(source)function
(repeat x)
(repeat n x)
Returns a lazy (infinite!, or length n if supplied) sequence of xs.
Examples
clojure
(ns clojure.test-clojure.reducers
(:require [clojure.core.reducers :as r]
[clojure.test.generative :refer (defspec)]
[clojure.data.generators :as gen])
(:use clojure.test))
(deftest test-fold-runtime-exception
(is (thrown? IndexOutOfBoundsException
(let [test-map-count 1234
k-fail (rand-int test-map-count)]
(r/fold (fn ([])
([ret [k v]])
([ret k v] (when (= k k-fail)
(throw (IndexOutOfBoundsException.)))))
(zipmap (range test-map-count) (repeat :dummy)))))))
clojure/core.typed
(ns clojure.core.typed.annotator.debug-macros
(:require [clojure.core.typed.annotator.util :refer [*debug*
*debug-depth*
current-time]])
)
(defmacro debug-flat
([msg]
`(when (= :all *debug*)
(print (str (apply str (repeat *debug-depth* " ")) *debug-depth* ": "))
~msg)))
hoplon/hoplon
(ns hoplon.binding
(:refer-clojure :exclude [binding bound-fn])
(:require [clojure.core :as clj]
[cljs.analyzer :as a]))
(defmacro binding
"See clojure.core/binding."
[bindings & body]
(let [env (assoc &env :ns (a/get-namespace a/*cljs-ns*))
value-exprs (take-nth 2 (rest bindings))
bind-syms (map #(:name (a/resolve-existing-var env %)) (take-nth 2 bindings))
bind-syms' (map (partial list 'quote) bind-syms)
set-syms (repeatedly (count bind-syms) gensym)
setfn (fn [x y]
{:push! `(fn []
(let [z# ~x]
(set! ~x ~y)
(fn [] (set! ~x z#))))})
thunkmaps (map setfn bind-syms set-syms)]
(a/confirm-bindings env bind-syms)
`(let [~@(interleave set-syms value-exprs)]
(hoplon.binding/push-thread-bindings ~(zipmap bind-syms' thunkmaps))
(try ~@body (finally (hoplon.binding/pop-thread-bindings))))))
hraberg/deuce
(ns deuce.emacs.macros
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c])
(:refer-clojure :exclude []))
(defun execute-kbd-macro (macro &optional count loopfunc)
"Execute MACRO as string of editor command characters.
If MACRO is a symbol, its function definition is used.
COUNT is a repeat count, or nil for once, or 0 for infinite loop.
(defun end-kbd-macro (&optional repeat loopfunc)
"Finish defining a keyboard macro.
The definition was started by M-x start-kbd-macro.
The macro is now available for use via M-x call-last-kbd-macro,
or it can be given a name with M-x name-last-kbd-macro and then invoked
under that name.
With numeric arg, repeat macro now that many times,
counting the definition just completed as the first repetition.
An argument of zero means repeat until error.
A prefix argument serves as a repeat count. Zero means repeat until error.
reborg/parallel
(require '[parallel.core :as p])
(require '[criterium.core :refer [bench quick-bench]])
(require '[clojure.core.reducers :as r])
(def small-overlapping
(into [] (map hash-map
(repeat :samplevalue)
(concat
(shuffle (range 0. 1e5))
(shuffle (range 0. 1e5))
(shuffle (range 0. 1e5))
(shuffle (range 0. 1e5))
(shuffle (range 0. 1e5))))))
(def big-overlapping
(into [] (map hash-map
(repeat :samplevalue)
(concat
(shuffle (range 6e4 1e5))
(shuffle (range 6e4 1e5))
(shuffle (range 6e4 1e5))
(shuffle (range 6e4 1e5))
(shuffle (range 6e4 1e5))))))
(def bigger-data
(into [] (map hash-map
(repeat :samplevalue)
(concat
(shuffle (range 0. 7e5))
(shuffle (range 0. 7e5))
(shuffle (range 0. 7e5))
(shuffle (range 0. 7e5))
(shuffle (range 0. 7e5))))))
findmyway/reinforcement-learning-an-introduction
;; @@
(ns rl.chapter04.grid-world
(:require [clojure.core.matrix :as m])
(:use [plotly-clj.core]))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
(let [N 4
reward -1
world (m/zero-matrix N N)
states (for [i (range N) j (range N)
:when (not (contains? #{[0 0] [(dec N) (dec N)]} [i j]))]
[i j])
actions [[-1 0] [1 0] [0 -1] [0 1]] ;; [:left :right :down :up]
prob (zipmap actions (repeat 0.25))
update-v (fn [w idx]
(apply + (map #(* (prob %)
(+ reward (get-in w (mapv + % idx) (get-in w idx))))
actions)))
iter-fn #(mapv vec (partition N (concat [0] (map (partial update-v %) states) [0])))
stop? (fn [[a b]] (< (m/abs (- (m/esum a) (m/esum b))) 0.0001))
converge #(ffirst (filter stop? (partition 2 %)))]
(-> (plotly)
(add-surface :z (converge (iterate iter-fn world)))
(plot "RL-figure-4-1" :fileopt "overwrite")
embed-url))
;; @@
;; =>
;;; {"type":"html","content":"<iframe height=\"600\" src=\"//plot.ly/~findmyway/120.embed\" width=\"800\"></iframe>","value":"pr'ed value"}
;; <=