liveBook · Manning

Quot

As explained in Clojure: The Essential Reference

quot is a Clojure function that returns the quotient of dividing two numbers, truncating any fractional part.

quot returns the quotient of dividing two numbers, truncating any fractional part. It is useful when whole items must be distributed without splitting them. section 5.7

Its contract is compact:

  • Accepts numeric num and div arguments. section 5.7
  • Returns the truncated quotient; a double input produces a double result. section 5.7
  • Throws ArithmeticException when div is zero. section 5.7

Basic division and container sizing

(quot 38 4) ;; 9 (quot 38. 4) ;; 9.0 For distributing 900 items among containers, combine quot with rem to detect an uneven division and increase the container size when needed; the resulting optimal size is 41.

(defn optimal-size [n m]
  (let [size (quot n m)                               ; #1
        left? (zero? (rem n m))]                      ; #2
    (if left?
      size
      (inc size))))

(optimal-size 900 22)                                 ; #3
;; 41

(partition-all (optimal-size 900 22) (range 900))  ; #4
;; ((0 1 2 3 ... 38 39 40) (41 42 43 ...
;; 79 80 81) ...  (82 83 84 ...

Shows quot composed with rem, zero?, inc, and partition-all to calculate and use a whole-container size. section 5.7

How Clojure: The Essential Reference covers it

How deep it goes
Defines inputs, truncation, numeric return types, and zero-division failure, while deferring detailed negative-number behavior.
Examples
Demonstrates integer and double division plus sizing containers for 900 items distributed across 22 containers.
What it assumes
Assumes basic numeric division and distinguishes quotient from remainder through rem and mod.
What you can do after
Apply via Clojure to compute truncated quotients and build whole-unit distribution logic with rem.
How it connects
Connects quotient calculation with rem, mod, zero?, inc, and partition-all.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.