liveBook · Manning

Range

As explained in Clojure: The Essential Reference

range is a Clojure function that generates a numeric sequence from a start value toward an end value using a specified step.

range generates numeric sequences for use with sequence-processing operations. Its arities support an infinite sequence, an end value, or explicit start, end, and step values. section 3.4.2

Use these rules to predict the result:

  • With no arguments, produces numbers from 0 toward positive infinity. section 3.4.2
  • With end, starts at 0 and stops before end; start defaults to 0 and step to 1. section 3.4.2
  • With three arguments, supports increasing or decreasing sequences; incompatible bounds produce an empty sequence. section 3.4.2
  • Accepts arbitrary-precision numeric values and throws ArityException for more than three arguments. section 3.4.2

Common ranges

(range 10) ;; (0 1 2 3 4 5 6 7 8 9) (range 0 20 2) ;; (0 2 4 6 8 10 12 14 16 18) (range -1 -20 -2) ;; (-1 -3 -5 -7 -9 -11 -13 -15 -17 -19)

How Clojure: The Essential Reference covers it

How deep it goes
Defines arities, defaults, stopping rules, direction, numeric precision, and invalid-arity behavior through examples.
Examples
Demonstrates integer, even, descending, fractional, nested, palindrome-index, and large-number ranges.
What it assumes
Assumes basic numbers and sequence operations while establishing numeric inputs, bounds, steps, and empty-result cases.
What you can do after
Apply it via Clojure to construct bounded, unbounded, ascending, descending, and fractional numeric sequences.
How it connects
Connects numeric generation with sequence processing, mapping, reduction, transduction, indexing, and arbitrary-precision arithmetic.

Also explained in

Compare how 8 books explain range →

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.