Back
doseq (clj)
(source)macro
(doseq seq-exprs & body)
Repeatedly executes body (presumably for side-effects) with
bindings and filtering as provided by "for". Does not retain
the head of the sequence. Returns nil.
Examples
clojure
(ns clojure.test-clojure.server
(:import java.util.Random)
(:require [clojure.test :refer :all])
(:require [clojure.core.server :as s]))
(deftest test-validate-opts
(check-invalid-opts {} "Missing required socket server property :name")
(check-invalid-opts {:name "a" :accept 'clojure.core/+} "Missing required socket server property :port")
(doseq [port [-1 "5" 999999]]
(check-invalid-opts {:name "a" :port port :accept 'clojure.core/+} (str "Invalid socket server port: " port)))
(check-invalid-opts {:name "a" :port 5555} "Missing required socket server property :accept"))
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))
(defmacro defequivtest
;; f is the core fn, r is the reducers equivalent, rt is the reducible ->
;; coll transformer
[name [f r rt] fns]
`(deftest ~name
(let [c# (range -100 1000)]
(doseq [fn# ~fns]
(is (= (~f fn# c#)
(~rt (~r fn# c#))))))))
clojure
(deftest division
(is (= clojure.core// /))
(binding [*ns* *ns*]
(eval '(do (ns foo
(:require [clojure.core :as bar])
(:use [clojure.test]))
(is (= clojure.core// bar//))))))
(deftest Instants
(testing "Instants are read as java.util.Date by default"
(is (= java.util.Date (class #inst "2010-11-12T13:14:15.666"))))
(let [s "#inst \"2010-11-12T13:14:15.666-06:00\""]
(binding [*data-readers* {'inst read-instant-date}]
(testing "read-instant-date produces java.util.Date"
(is (= java.util.Date (class (read-string s)))))
(testing "java.util.Date instants round-trips"
(is (= (-> s read-string)
(-> s read-string pr-str read-string))))
(testing "java.util.Date instants round-trip throughout the year"
(doseq [month (range 1 13) day (range 1 29) hour (range 1 23)]
(let [s (format "#inst \"2010-%02d-%02dT%02d:14:15.666-06:00\"" month day hour)]
(is (= (-> s read-string)
(-> s read-string pr-str read-string))))))
(testing "java.util.Date handling DST in time zones"
(let [dtz (TimeZone/getDefault)]
(try
;; A timezone with DST in effect during 2010-11-12
(TimeZone/setDefault (TimeZone/getTimeZone "Australia/Sydney"))
(is (= (-> s read-string)
(-> s read-string pr-str read-string)))
(finally (TimeZone/setDefault dtz)))))
(testing "java.util.Date should always print in UTC"
(let [d (read-string s)
pstr (print-str d)
len (.length pstr)]
(is (= (subs pstr (- len 7)) "-00:00\"")))))
(binding [*data-readers* {'inst read-instant-calendar}]
(testing "read-instant-calendar produces java.util.Calendar"
(is (instance? java.util.Calendar (read-string s))))
(testing "java.util.Calendar round-trips"
(is (= (-> s read-string)
(-> s read-string pr-str read-string))))
(testing "java.util.Calendar remembers timezone in literal"
(is (= "#inst \"2010-11-12T13:14:15.666-06:00\""
(-> s read-string pr-str)))
(is (= (-> s read-string)
(-> s read-string pr-str read-string))))
(testing "java.util.Calendar preserves milliseconds"
(is (= 666 (-> s read-string
(.get java.util.Calendar/MILLISECOND)))))))
(let [s "#inst \"2010-11-12T13:14:15.123456789\""
s2 "#inst \"2010-11-12T13:14:15.123\""
s3 "#inst \"2010-11-12T13:14:15.123456789123\""]
(binding [*data-readers* {'inst read-instant-timestamp}]
(testing "read-instant-timestamp produces java.sql.Timestamp"
(is (= java.sql.Timestamp (class (read-string s)))))
(testing "java.sql.Timestamp preserves nanoseconds"
(is (= 123456789 (-> s read-string .getNanos)))
(is (= 123456789 (-> s read-string pr-str read-string .getNanos)))
;; truncate at nanos for s3
(is (= 123456789 (-> s3 read-string pr-str read-string .getNanos))))
(testing "java.sql.Timestamp should compare nanos"
(is (= (read-string s) (read-string s3)))
(is (not= (read-string s) (read-string s2)))))
(binding [*data-readers* {'inst read-instant-date}]
(testing "read-instant-date should truncate at milliseconds"
(is (= (read-string s) (read-string s2) (read-string s3))))))
(let [s "#inst \"2010-11-12T03:14:15.123+05:00\""
s2 "#inst \"2010-11-11T22:14:15.123Z\""]
(binding [*data-readers* {'inst read-instant-date}]
(testing "read-instant-date should convert to UTC"
(is (= (read-string s) (read-string s2)))))
(binding [*data-readers* {'inst read-instant-timestamp}]
(testing "read-instant-timestamp should convert to UTC"
(is (= (read-string s) (read-string s2)))))
(binding [*data-readers* {'inst read-instant-calendar}]
(testing "read-instant-calendar should preserve timezone"
(is (not= (read-string s) (read-string s2)))))))
(deftest preserve-read-cond-test
(let [x (read-string {:read-cond :preserve} "#?(:clj foo :cljs bar)" )]
(is (reader-conditional? x))
(is (not (:splicing? x)))
(is (= :foo (get x :no-such-key :foo)))
(is (= (:form x) '(:clj foo :cljs bar)))
(is (= x (reader-conditional '(:clj foo :cljs bar) false))))
(let [x (read-string {:read-cond :preserve} "#?@(:clj [foo])" )]
(is (reader-conditional? x))
(is (:splicing? x))
(is (= :foo (get x :no-such-key :foo)))
(is (= (:form x) '(:clj [foo])))
(is (= x (reader-conditional '(:clj [foo]) true))))
(is (thrown-with-msg? RuntimeException #"No reader function for tag"
(read-string {:read-cond :preserve} "#js {:x 1 :y 2}" )))
(let [x (read-string {:read-cond :preserve} "#?(:cljs #js {:x 1 :y 2})")
[platform tl] (:form x)]
(is (reader-conditional? x))
(is (tagged-literal? tl))
(is (= 'js (:tag tl)))
(is (= {:x 1 :y 2} (:form tl)))
(is (= :foo (get tl :no-such-key :foo)))
(is (= tl (tagged-literal 'js {:x 1 :y 2}))))
(testing "print form roundtrips"
(doseq [s ["#?(:clj foo :cljs bar)"
"#?(:cljs #js {:x 1, :y 2})"
"#?(:clj #clojure.test_clojure.reader.TestRecord [42 85])"]]
(is (= s (pr-str (read-string {:read-cond :preserve} s)))))))
jepsen-io/jepsen
(ns yugabyte.ycql.bank
(:refer-clojure :exclude [test])
(:require [clojure.tools.logging :refer [debug info warn]]
[clojure.core.reducers :as r]
[jepsen.client :as client]
[jepsen.checker :as checker]
[jepsen.generator :as gen]
[jepsen.tests.bank :as bank]
[jepsen.checker.timeline :as timeline]
[knossos.op :as op]
[clojurewerkz.cassaforte.client :as cassandra]
[clojurewerkz.cassaforte.cql :as cql]
[clojurewerkz.cassaforte.query :as q :refer :all]
[yugabyte.ycql.client :as c]))
(c/defclient CQLBank keyspace []
(setup! [this test]
(c/create-transactional-table
conn table-name
(q/if-not-exists)
(q/column-definitions {:id :int
:balance :bigint
:primary-key [:id]}))
(info "Creating accounts")
(c/with-retry
(cql/insert-with-ks conn keyspace table-name
{:id (first (:accounts test))
:balance (:total-amount test)})
(doseq [a (rest (:accounts test))]
(cql/insert conn table-name
{:id a, :balance 0}))))
;; Shouldn't be used until we support transactions with selects.
(c/defclient CQLMultiBank keyspace []
(setup! [this test]
(info "Creating accounts")
(doseq [a (:accounts test)]
(info "Creating table" a)
(c/create-transactional-table
conn (str table-name a)
(q/if-not-exists)
(q/column-definitions {:id :int
:balance :bigint
:primary-key [:id]}))
clojure/core.async
;; The clojure.core.async namespace contains the public API.
(require '[clojure.core.async :as async :refer :all])
(let [n 1000
cs (repeatedly n chan)
begin (System/currentTimeMillis)]
(doseq [c cs] (go (>! c "hi")))
(dotimes [i n]
(let [[v c] (alts!! cs)]
(assert (= "hi" v))))
(println "Read" n "msgs in" (- (System/currentTimeMillis) begin) "ms"))
hraberg/deuce
(ns deuce.emacs
(:require [clojure.core :as c]
[deuce.emacs-lisp :as el]
[deuce.emacs-lisp.globals :as globals])
(:refer-clojure :only [])
(:use [deuce.emacs-lisp :only [and apply-partially catch cond condition-case defconst define-compiler-macro defmacro
defun defvar function if interactive lambda let let* or prog1 prog2 progn quote
save-current-buffer save-excursion save-restriction setq setq-default
unwind-protect while throw]]
[deuce.emacs.alloc]
[deuce.emacs.buffer]
[deuce.emacs.bytecode]
[deuce.emacs.callint]
[deuce.emacs.callproc]
[deuce.emacs.casefiddle]
[deuce.emacs.casetab]
[deuce.emacs.category]
[deuce.emacs.ccl]
[deuce.emacs.character]
[deuce.emacs.charset]
[deuce.emacs.chartab]
[deuce.emacs.cmds]
[deuce.emacs.coding]
[deuce.emacs.composite]
[deuce.emacs.data]
[deuce.emacs.dired]
[deuce.emacs.dispnew]
[deuce.emacs.doc]
[deuce.emacs.editfns]
[deuce.emacs.emacs]
[deuce.emacs.eval]
[deuce.emacs.fileio]
[deuce.emacs.filelock]
[deuce.emacs.floatfns]
[deuce.emacs.fns]
[deuce.emacs.font]
[deuce.emacs.frame]
[deuce.emacs.indent]
[deuce.emacs.insdel]
[deuce.emacs.keyboard]
[deuce.emacs.keymap]
[deuce.emacs.lread]
[deuce.emacs.macros]
[deuce.emacs.marker]
[deuce.emacs.menu]
[deuce.emacs.minibuf]
[deuce.emacs.print]
[deuce.emacs.process]
[deuce.emacs.search]
[deuce.emacs.syntax]
[deuce.emacs.term]
[deuce.emacs.terminal]
[deuce.emacs.textprop]
[deuce.emacs.undo]
[deuce.emacs.window]
[deuce.emacs.xdisp]
[deuce.emacs.xfaces]
[deuce.emacs.xml]))
;; self-insert-command for standard keys setup in cmds.c
(define-key globals/global-map "\\C-i" 'self-insert-command)
(c/doseq [n (c/range 32 (c/inc 127))]
(define-key globals/global-map (make-string 1 n) 'self-insert-command))
(c/doseq [n (c/range 160 (c/inc 256))]
(define-key globals/global-map (make-string 1 n) 'self-insert-command))
hraberg/deuce
(ns deuce.emacs.eval
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[deuce.emacs.alloc :as alloc]
[deuce.emacs.data :as data]
[deuce.emacs-lisp.cons :as cons]
[deuce.emacs-lisp :as el])
(:import [clojure.lang Var])
(:refer-clojure :exclude [apply eval macroexpand]))
Do not use `make-local-variable' to make a hook variable buffer-local.
Instead, use `add-hook' and specify t for the LOCAL argument."
(doseq [hook hooks]
(run-hook-with-args hook)))
typedclojure/typedclojure
(ns ^:no-doc typed.clj.ext.clojure.core__doseq
"Typing rules clojure.core/doseq"
(:require [clojure.core.typed.contract-utils :as con]
[clojure.core.typed.errors :as err]
[typed.clj.checker.check :refer [check-expr]]
[typed.clj.checker.parse-unparse :as prs]
[typed.clj.analyzer.passes.emit-form :as emit-form]
[typed.clj.analyzer.utils :as ana-utils]
[typed.clj.ext.clojure.core__for :as ext-for]
[typed.clj.ext.clojure.core__let :as ext-let]
[typed.cljc.analyzer :as ana2]
[typed.cljc.checker.check.let :as let]
[typed.cljc.checker.check-below :as below]
[typed.cljc.checker.check.if :as if]
[typed.cljc.checker.filter-ops :as fo]
[typed.cljc.checker.lex-env :as lex]
[typed.cljc.checker.var-env :as var-env]
[typed.cljc.checker.type-rep :as r]
[typed.cljc.checker.type-ctors :as c]
[typed.cljc.checker.cs-gen :as cgen]
[typed.cljc.checker.utils :as u]
[typed.cljc.checker.check.unanalyzed :refer [defuspecial]]))
;;==================
;; clojure.core/doseq
(defuspecial defuspecial__doseq
"defuspecial implementation for clojure.core/doseq"
[{ana-env :env :keys [form] :as expr} expected]
(let [_ (assert (<= 2 (count form)) form)
[args-syn & body-syns] (next form)
{:keys [new-syms expanded-bindings prop-env ana-env reachable]}
(ext-for/check-list-comprehension-binder
{:form form
:args-syn args-syn
:ana-env ana-env
:prop-env (lex/lexical-env)})
expr (-> expr
(update :form
(fn [form]
(-> (map-indexed
(fn [i args-syn]
;; add back short-circuited args
(if (= 1 i)
expanded-bindings
args-syn))
form)
(with-meta (meta form))))))]
(if-not reachable
(assoc expr
u/expr-type (below/maybe-check-below
(r/ret r/-nil
(fo/-false-filter))
expected))
(let [cbody (var-env/with-lexical-env prop-env
(-> `(do ~@body-syns)
(ana2/unanalyzed ana-env)
check-expr))
expr (-> expr
(update :form
(fn [form]
(-> form
vec
(subvec 0 2)
(conj (emit-form/emit-form cbody))
list*
(with-meta (meta form))))))]
(assoc expr
u/expr-type (below/maybe-check-below
(r/ret r/-nil
(fo/-false-filter))
expected))))))