Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (60 sloc) 3.85 KB
<div class="doc-item" id="doc-686"><h2 class="doc-item-name">doseq<span class="namespace">(clojure.core)</span></h2><p class="macro">Macro</p><ul class="var-arglists"><li>(<span class="var-name">doseq</span> seq-exprs &amp; body)</li></ul><div class="var-docstring"><p>Repeatedly executes body (presumably for side-effects) with
bindings and filtering as provided by &quot;for&quot;. Does not retain
the head of the sequence. Returns nil.</p></div><div class="var-source"><pre>; clojure/core.clj:1858
(defmacro doseq
[seq-exprs &amp; body]
(assert-args doseq
(vector? seq-exprs) &quot;a vector for its binding&quot;
(even? (count seq-exprs)) &quot;an even number of forms in binding vector&quot;)
(let [step (fn step [recform exprs]
(if-not exprs
[true `(do ~@body)]
(let [k (first exprs)
v (second exprs)]
(if (keyword? k)
(let [steppair (step recform (nnext exprs))
needrec (steppair 0)
subform (steppair 1)]
(= k :let) [needrec `(let ~v ~subform)]
(= k :while) [false `(when ~v
~@(when needrec [recform]))]
(= k :when) [false `(if ~v
~@(when needrec [recform]))
(let [seq- (gensym &quot;seq_&quot;)
chunk- (with-meta (gensym &quot;chunk_&quot;)
{:tag 'clojure.lang.IChunk})
count- (gensym &quot;count_&quot;)
i- (gensym &quot;i_&quot;)
recform `(recur (next ~seq-) nil (int 0) (int 0))
steppair (step recform (nnext exprs))
needrec (steppair 0)
subform (steppair 1)
`(recur ~seq- ~chunk- ~count- (unchecked-inc ~i-))
steppair-chunk (step recform-chunk (nnext exprs))
subform-chunk (steppair-chunk 1)]
`(loop [~seq- (seq ~v), ~chunk- nil,
~count- (int 0), ~i- (int 0)]
(if (&lt; ~i- ~count-)
(let [~k (.nth ~chunk- ~i-)]
~@(when needrec [recform-chunk]))
(when-let [~seq- (seq ~seq-)]
(if (chunked-seq? ~seq-)
(let [c# (chunk-first ~seq-)]
(recur (chunk-rest ~seq-) c#
(int (count c#)) (int 0)))
(let [~k (first ~seq-)]
~@(when needrec [recform]))))))])))))]
(nth (step nil (seq seq-exprs)) 1)))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="">Eclipse Public License 1.0</a>, which can be found in the file
epl-v10.html at the root of this distribution. By using this software
in any fashion, you are agreeing to be bound by the terms of this
license. You must not remove this notice, or any other, from this
Something went wrong with that request. Please try again.