chickadee » clojurian » doto

(doto val (proc args ...) ...)syntax

Inserts val as the first argument of each (proc args ...) clause (i.e. right after proc). Returns val. This is useful e.g. for mutating a record on initialization.

Example:

(define boolean-vector
  (doto (make-vector 100)
        (vector-fill! #t 0 50)
        (vector-fill! #f 50)))
=>

(define boolean-vector
  (let ((vec (make-vector 100)))
    (vector-fill! vec #t 0 50)
    (vector-fill! vec #f 50)
    vec))