Utility functions.
Utility functions.
(assert-args & pairs)Assert each predicate/message pair, where predicates are arbitrary
expressions and messages are printable values. Evaluation stops at the
first falsey predicate and strictly throws java.lang.IllegalArgumentException;
exceptions from predicate expressions propagate unchanged. Expanding p
predicate/message pairs takes O(p) time and emits O(p) code.
Assert each predicate/message pair, where predicates are arbitrary expressions and messages are printable values. Evaluation stops at the first falsey predicate and strictly throws `java.lang.IllegalArgumentException`; exceptions from predicate expressions propagate unchanged. Expanding `p` predicate/message pairs takes O(p) time and emits O(p) code.
(bytes-hash-code bytes)(bytes-hash-code bytes initial)(bytes-hash-code bytes offset length)(bytes-hash-code bytes offset length initial)Calculate a hash code for part of primitive byte array bytes. The
two-argument form takes an initial hash; the three-argument form takes
offset and length; the four-argument form takes all three numeric values.
Numeric arguments accept java.lang.Number values coercible to long.
This is strict about types and bounds. A nil array or numeric argument throws
java.lang.NullPointerException; a wrong array or non-number type throws
java.lang.ClassCastException; accessing a range outside the array throws
java.lang.ArrayIndexOutOfBoundsException; overflow in offset + length
throws java.lang.ArithmeticException; and a numeric argument outside the
long range throws java.lang.IllegalArgumentException. A non-positive
length reads no bytes and returns the initial hash. The operation is
O(max(length, 0)) time and O(1) additional space.
Calculate a hash code for part of primitive byte array `bytes`. The two-argument form takes an initial hash; the three-argument form takes `offset` and `length`; the four-argument form takes all three numeric values. Numeric arguments accept `java.lang.Number` values coercible to `long`. This is strict about types and bounds. A nil array or numeric argument throws `java.lang.NullPointerException`; a wrong array or non-number type throws `java.lang.ClassCastException`; accessing a range outside the array throws `java.lang.ArrayIndexOutOfBoundsException`; overflow in `offset + length` throws `java.lang.ArithmeticException`; and a numeric argument outside the long range throws `java.lang.IllegalArgumentException`. A non-positive `length` reads no bytes and returns the initial hash. The operation is O(max(length, 0)) time and O(1) additional space.
(case-expr e & clauses)Like case, but only supports individual test expressions, which are
evaluated at macro-expansion time. e, result forms, and the optional final
default are arbitrary expressions. Exceptions from evaluating a test
expression propagate unchanged; invalid or duplicate case constants throw
java.lang.IllegalArgumentException during macro expansion. Expanding c
clauses takes O(c) time and emits O(c) code.
Like `case`, but only supports individual test expressions, which are evaluated at macro-expansion time. `e`, result forms, and the optional final default are arbitrary expressions. Exceptions from evaluating a test expression propagate unchanged; invalid or duplicate `case` constants throw `java.lang.IllegalArgumentException` during macro expansion. Expanding `c` clauses takes O(c) time and emits O(c) code.
(doto-let bindings & body)bindings => binding-form expr
Evaluates expr, and evaluates body with its result bound to the binding-form.
Returns the result of expr. The binding vector must contain exactly one binding
and expression; otherwise macro expansion throws
java.lang.IllegalArgumentException. body accepts arbitrary forms; exceptions
from expr or body propagate unchanged. Expansion is O(b) in the number of
body forms and emits O(b) code.
bindings => binding-form expr Evaluates expr, and evaluates body with its result bound to the binding-form. Returns the result of expr. The binding vector must contain exactly one binding and expression; otherwise macro expansion throws `java.lang.IllegalArgumentException`. `body` accepts arbitrary forms; exceptions from `expr` or `body` propagate unchanged. Expansion is O(b) in the number of body forms and emits O(b) code.
(ffilter pred coll)Return the first item in coll for which (pred item) is true. coll is a
seqable value or nil, and pred implements clojure.lang.IFn. This is
lenient when no item matches and returns nil. A non-seqable coll throws
java.lang.IllegalArgumentException; a non-function pred throws
java.lang.ClassCastException when invoked. Exceptions from pred propagate
unchanged. It takes O(k) time after examining k items and O(1) space.
Return the first item in `coll` for which `(pred item)` is true. `coll` is a seqable value or `nil`, and `pred` implements `clojure.lang.IFn`. This is lenient when no item matches and returns `nil`. A non-seqable `coll` throws `java.lang.IllegalArgumentException`; a non-function `pred` throws `java.lang.ClassCastException` when invoked. Exceptions from `pred` propagate unchanged. It takes O(k) time after examining `k` items and O(1) space.
(ignore-errors & body)Evaluate body and return its result, or nil if it throws a
java.lang.Exception (errors are not caught). The macro accepts any body
forms. It is lenient for Exception subclasses; any java.lang.Error or
other Throwable propagates unchanged.
Evaluate `body` and return its result, or `nil` if it throws a `java.lang.Exception` (errors are not caught). The macro accepts any body forms. It is lenient for `Exception` subclasses; any `java.lang.Error` or other `Throwable` propagates unchanged.
(longest-run x coll)Find the longest run of the value x in the collection coll. Returns the
pair of the starting index and length on success and nil on failure. When
multiple runs have the same maximum length, returns the first such run.
coll is any finite seqable value or nil. Absence is lenient and returns
nil; a non-seqable coll throws java.lang.IllegalArgumentException. The
operation is O(n) time and O(r) space for n items and longest-run length
r.
Find the longest run of the value x in the collection coll. Returns the pair of the starting index and length on success and nil on failure. When multiple runs have the same maximum length, returns the first such run. `coll` is any finite seqable value or `nil`. Absence is lenient and returns `nil`; a non-seqable `coll` throws `java.lang.IllegalArgumentException`. The operation is O(n) time and O(r) space for `n` items and longest-run length `r`.
(sbyte x)Return the signed byte that numeric value x represents, subtracting 256
once when x is greater than 127. x accepts any java.lang.Number;
fractional values are truncated by byte conversion. nil throws
java.lang.NullPointerException, a non-number throws
java.lang.ClassCastException, and an adjusted value outside the signed-byte
range throws java.lang.IllegalArgumentException. This is O(1).
Return the signed byte that numeric value `x` represents, subtracting 256 once when `x` is greater than 127. `x` accepts any `java.lang.Number`; fractional values are truncated by byte conversion. `nil` throws `java.lang.NullPointerException`, a non-number throws `java.lang.ClassCastException`, and an adjusted value outside the signed-byte range throws `java.lang.IllegalArgumentException`. This is O(1).
(ubyte x)Return the unsigned number represented by the low eight bits of x. x
accepts any java.lang.Number coercible to long; fractional values are
truncated. This is strict about type: nil throws
java.lang.NullPointerException and a non-number throws
java.lang.ClassCastException; a numeric value outside the long range throws
java.lang.IllegalArgumentException. This is O(1).
Return the unsigned number represented by the low eight bits of `x`. `x` accepts any `java.lang.Number` coercible to `long`; fractional values are truncated. This is strict about type: `nil` throws `java.lang.NullPointerException` and a non-number throws `java.lang.ClassCastException`; a numeric value outside the long range throws `java.lang.IllegalArgumentException`. This is O(1).
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |