(= obj1 obj2)
Supported by all objects. Returns true if obj1 equals obj2, false if not. Same as Java obj1.equals(obj2) except it also works for nil, and compares numbers in a type-independent manner. Clojure's immutable data structures define equals() (and thus =) as a value, not an identity, comparison.
(not= obj1 obj2)
Same as (not (= obj1 obj2))
(apply f args* argseq)
Applies fn f to the argument list formed by prepending args to argseq.
(partial f args+)
Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args.
user=> (map (partial + 2) [1 2 3])
(3 4 5)
(comp fns+)
Takes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc.
((comp a b c) x y z) ==> (a (b (c x y z)))
(nil? x)
Returns true if x is nil, false otherwise.
(not x)
Returns true if x is logical false, false otherwise.
(false? x)
Returns true if x is the value false, false otherwise.
(true? x)
Returns true if x is the value true, false otherwise.
(complement f)
Takes a fn f and returns a fn that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.
(constantly x)
Returns a function that takes any number of arguments and returns x.
(identical? x y)
Reference comparison. Returns true if x is the same object as y, false otherwise.
(identity x)
Returns x.
(str)
(str x)
(str x & more)
With no args, returns "". With one arg x, returns x.toString(). (str nil) returns ""
(time expr) - macro
Evaluates expr and prints the time it took. Returns the value of expr.
(dotimes name n body)
Macro. Repeatedly executes body (presumably for side-effects) with name bound to integers from 0 through n-1.(comparator pred)
Returns an implementation of java.util.Comparator based upon pred.
(symbol name-string)
(symbol namespace-string name-string)
(keyword name-string)
(keyword namespace-string name-string)
Returns a Symbol or Keyword with the given namespace and name. Do not use : in the keyword strings, it will be added automatically.
(line-seq rdr)
Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader.
(pr object*)
(prn object*)
(print object*)
(println object*)
(pr-str object*)
(prn-str object*)
(print-str object*)
(println-str object*)
Prints the object(s) to the output stream that is the current value of *out*. The -str versions bind *out* to a StringWriter, print to that, and return the resulting string. pr prints the object(s), separated by spaces if there is more than one. prn does the same and follows it with a newline. print and println call pr and prn respectively, with *print-readably* (which defaults to :t) bound to nil, which causes strings to print without surrounding quotes or any escape character encoding, and characters to print without the leading '\', or any escape character encoding. By default, pr and prn print in a way that objects can be read by the reader, while print and println produce output for human consumption. When *print-readably* is non-nil, the printing of metadata is toggled by *print-meta*, which defaults to nil.
(with-out-str exprs)
Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls.
(newline)
Writes a newline to the output stream that is the current value of *out*
(with-open name init-expr body)
Macro. Evaluates body in a try expression with name bound to the value of init-expr, and a finally clause that calls(. name (close)).
(assert expr)
Macro. Evaluates expr and throws an exception if it does not evaluate to logical true.(string? x)
(symbol? x)
(map? x)
(seq? x)
(vector? x)
Type predicates. Return true if x is a String, Symbol, or implements IPersistentMap, ISeq, or IPersistentVector respectively.Regex Support
Compiled regex patterns are supported via the#"pattern" reader macro. The following functions expect such compiled patterns.
(re-matcher pattern string)
Returns an instance of java.util.regex.Matcher, for use, e.g. inre-find.
(re-find pattern string)
(re-find matcher)
Returns the next regex match, if any, of string to pattern, using java.util.regex.Matcher.find(). Usesre-groups to return the groups.
(re-matches pattern string)
Returns the match, if any, of string to pattern, using java.util.regex.Matcher.matches(). Usesre-groups to return the groups.
(re-groups matcher)
Returns the groups from the most recent match/find. If there are no nested groups, returns a string of the entire match. If there are nested groups, returns a vector of the groups, the first element being the entire match.(re-seq pattern string)
Returns a lazy sequence of successive matches of pattern in string, using java.util.regex.Matcher.find(), each such match processed with re-groups.
Some examples:
(re-seq #"[0-9]+" "abs123def345ghi567")
-> ("123" "345" "567")
(re-find #"([-+]?[0-9]+)/([0-9]+)" "22/7")
-> ["22/7" "22" "7"]
(let [[a b c] (re-matches #"([-+]?[0-9]+)/([0-9]+)" "22/7")]
[a b c])
-> ["22/7" "22" "7"]