std.lib.foundation

*sep*

dynamic

+init+

->

macro

added in 3.0

(-> expr & forms)

like -> but with % as placeholder

(-> 1 inc (- 10 %)) => 8

->>

macro

added in 3.0

(->> expr & forms)

like ->> but with % as placeholder

(-> 1 inc (- % 10)) => -8

aget

added in 3.0

(aget arr i)

typesafe aget

(aget (int-array 1 2 3) 2) => 3

applym

macro

added in 3.0

(applym macro & args)

Allow macros to be applied to arguments just like functions

(applym const ’((+ 1 2))) => 3

(macroexpand ’(applym const ’((+ 1 2)))) => 3

array?

added in 3.0

(array? x)(array? cls x)

checks if object is a primitive array

(array? (into-array [])) => true

(array? String (into-array “a” “b” “c”)) => true

atom?

added in 3.0

(atom? obj)

Returns true if x is of type clojure.lang.Atom.

(atom? (atom nil)) => true

bigdec?

added in 3.0

(bigdec? x)

Returns true if x is of type java.math.BigDecimal.

(bigdec? 1M) => true (bigdec? 1.0) => false

bigint?

added in 3.0

(bigint? x)

Returns true if x is of type clojure.lang.BigInt.

(bigint? 1N) => true (bigint? 1) => false

byte?

added in 3.0

(byte? x)

Returns true if x is of type java.lang.Byte

(byte? (byte 1)) => true

call

added in 3.0

(call obj)(call obj f)(call obj f v1)(call obj f v1 v2)(call obj f v1 v2 v3)(call obj f v1 v2 v3 v4)(call obj f v1 v2 v3 v4 & vs)

like invoke but reverses the function and first argument

(call 2) => 2

(call 2 + 1 2 3) => 8

code-column

macro

added in 3.0

(code-column)

gets the current code column

(code-column) => 3

code-line

macro

added in 3.0

(code-line)

gets the current code line

(code-line) => number?

code-ns

macro

added in 3.0

(code-ns)

returns the current namespace the code is in

(code-ns) => ’std.lib.foundation_test

comparable?

added in 3.0

(comparable? x y)

Returns true if x and y both implements java.lang.Comparable.

(comparable? 1 1) => true

concatv

added in 4.0

(concatv & args)

concats two seqs as vector

const

macro

added in 3.0

(const body)

converts an expression into a constant at compile time

(const (+ 1 2)) => 3

(macroexpand ’(const (+ 1 2))) => 3

counter

added in 3.0

(counter)(counter n)

creates a counter

(pr-str (counter)) => “#counter{-1}”

date

added in 3.0

(date)(date t)

creates a new date

(date 1000) => #inst “1970-01-01T00:00:01.000-00:00”

dec!

macro

added in 3.0

(dec! counter)(dec! counter n)

decrements the counter

@(doto (counter 10) (dec! 10)) => 0

def.m

macro

added in 4.0

(def.m syms call)

defs multiple vars

demunge

added in 3.0

(demunge name)

demunges an input to be nicer looking

(demunge ;;; (munge “+test!”) “PLUS_test_BANG”) => “+test!”

edn

added in 3.0

(edn obj)

prints then reads back the string

((juxt type (comp type edn)) (symbol “:hello”)) => clojure.lang.Symbol clojure.lang.Keyword

edn?

added in 3.0

(edn? x)

checks if an entry is valid edn

(edn? 1) => true

(edn? {}) => true

(edn? (java.util.Date.)) => false

error

macro

added in 3.0

(error message)(error message data)

throws an error with message

(error “Error”) => (throws)

F

added in 3.0

(F & args)

returns false for any combination of input args

(F) => false

flake

added in 3.0

(flake)

returns a unique, time incremental id

(flake) ;; “4Wv-T47LftnVlHhhh00JYuU15NCuNLcr” => string?

hash-code

added in 3.0

(hash-code obj)

returns the hash code of an object

hash-id

added in 3.0

(hash-id obj)

returns the actual memory related id for an object

ideref?

added in 3.0

(ideref? obj)

checks if

(ideref? (volatile! 0)) => true (ideref? (promise)) => true

inc!

macro

added in 3.0

(inc! counter)(inc! counter n)

increments the counter

@(doto (counter) (inc!) (inc! 10)) => 10

instant

added in 3.0

(instant)(instant val)

returns a java.util.Date object

(instant) => #(instance? java.util.Date %)

(instant 0) => #inst “1970-01-01T00:00:00.000-00:00”

intern-all

macro

added in 3.0

(intern-all & nss)

adds a namespace to current

intern-form

added in 3.0

(intern-form ns sym)(intern-form ns sym meta)

creates base form for intern-in and intern-all

(intern-form ’std.lib ’std.lib.foundation/unfold)

intern-in

macro

added in 3.0

(intern-in ns? & syms)

adds a function to current

intern-var

added in 3.0

(intern-var ns sym var)(intern-var ns sym var ext)

interns a var in sym

invoke

added in 3.0

(invoke f)(invoke f & args)

provides a caller for the IFn

(invoke (fn [](+ 1 2 3))) => 6

iobj?

added in 3.0

(iobj? x)

checks if a component is instance of clojure.lang.IObj

(iobj? 1) => false

(iobj? {}) => true

iref?

added in 3.0

(iref? obj)

Returns true if x is of type clojure.lang.IRef.

(iref? (atom 0)) => true

keyword

added in 3.0

(keyword obj)

returns the keyword value

(keyword :hello) => :hello

(keyword “hello”) => :hello

long?

added in 3.0

(long? x)

Returns true if x is of type java.lang.Long

(long? 1) => true (long? 1N) => false

lsubs

added in 4.0

(lsubs s n)

substring from last

(lsubs “hello-world” 4) => “hello-w”

NIL

added in 3.0

(NIL & args)

returns nil for any combination of input args

(NIL) => nil

parse-double

added in 3.0

(parse-double s)

parses a double from string

(parse-double “100”) => 100.0

(parse-double “100.123”) => 100.123

parse-long

added in 3.0

(parse-long s)

parses a long from string

(parse-long “100”) => 100

re-create

regexp?

added in 3.0

(regexp? x)

Returns true if x implements clojure.lang.IPersistentMap.

(regexp? #“\d+”) => true

reset!

added in 3.0

(reset! counter n)

resets a counter to the given value

(reset! (counter 10) 5) => 5

resolve-namespaced

added in 4.0

(resolve-namespaced x)

resolves a namespaced symbol

set!

macro

added in 3.0

(set! sym val)

sets a var without changing current meta

(std.lib.foundation/set! -lost- 1)

short?

added in 3.0

(short? x)

Returns true if x is of type java.lang.Short

(short? (short 1)) => true

sid

added in 3.0

(sid)

returns a short id string

(sid) ;; “t8a6euzk9usy” => string?

sid-tag

(sid-tag tag)

string

added in 3.0

(string obj)

creates a string from a byte array

(string (.getBytes “Hello”)) => “Hello”

strn

added in 3.0

(strn obj)(strn obj & more)

returns the strn value

(strn :hello) => “hello”

(strn “hello”) => “hello”

suppress

macro

added in 3.0

(suppress body)(suppress body catch-val)

Suppresses any errors thrown in the body.

(suppress (throw (ex-info “Error” {}))) => nil

(suppress (throw (ex-info “Error” {})) :error) => :error

(suppress (throw (ex-info “Error” {})) (fn ^Throwable e (.getMessage e))) => “Error”

T

added in 3.0

(T & args)

returns true for any combination of input args

(T) => true

template-bulk

macro

added in 4.0

(template-bulk [tmpl-fn & [tmpl-meta]] entries)

template-entries but for heavy usage

template-ensure

added in 4.0

(template-ensure syms vars)

ensures that the templated entries are the same as the input

template-entries

macro

added in 3.0

(template-entries [tmpl-fn & [tmpl-meta]] & entries)

uses a template function to produce entries

template-meta

added in 3.0

(template-meta)

returns the intern template meta

template-vars

macro

added in 3.0

(template-vars [tmpl-fn & [tmpl-meta]] & syms)

adds a function to current given var and arguments

thread-form

added in 3.0

(thread-form forms transform-fn)

helper function to ‘->’ and ‘->>’

(thread-form ’(+ 1) dec (fn form(concat form ’%))) => ’(% (+ 1 %) % (dec %))

thread?

added in 3.0

(thread? obj)

Returns true is x is a thread

(thread? (Thread/currentThread)) => true

throwable?

added in 3.0

(throwable? obj)

checks that object is a Throwable

(throwable? (ex-info “hello” {})) => true

trace

macro

added in 3.0

(trace)(trace val)

prints out the item and a program trace

(trace “Error”) => Throwable

U

added in 3.0

(U f)

U Combinator

((U factorial) 5) => 120

unbound?

added in 3.0

(unbound? obj)

checks if a variable is unbound

(declare -lost-)

(unbound? -lost-) = true

uri

added in 3.0

(uri path)

returns a java.net.UrI object

(uri “http://www.google.com”) => java.net.URI

url

added in 3.0

(url path)

retruns a java.net.URL object

(url “http://www.google.com”) => java.net.URL

url?

added in 3.0

(url? x)

Returns true if x is of type java.net.URL.

(url? (java.net.URL. “file:/Users/chris/Development”)) => true

uuid

added in 3.0

(uuid)(uuid id)(uuid msb lsb)

returns a java.util.UUID object

(uuid) => #(instance? java.util.UUID %)

(uuid “00000000-0000-0000-0000-000000000000”) => #uuid “00000000-0000-0000-0000-000000000000”

uuid-nil

added in 4.0

(uuid-nil)

constructs a nil uuid

var-sym

added in 3.0

(var-sym var)

converts a var to a symbol

(var-sym #’var-sym) => ’std.lib.foundation/var-sym

with-ex

macro

added in 4.0

(with-ex & body)

gets the exception data in a form

(with-ex (throw (ex-info “Error” {:hello “1”}))) => {:hello “1”}

with-retry

macro

added in 4.0

(with-retry [limit sleep] & body)

with retry macro

with-retry-fn

added in 4.0

(with-retry-fn limit sleep f)

with a retry function

with-thrown

macro

added in 4.0

(with-thrown & body)

gets the exception data in a form

(ex-data (with-thrown (throw (ex-info “Error” {:hello “1”})))) => {:hello “1”}

with:template-meta

macro

added in 3.0

(with:template-meta meta & body)

binds the template meta (for testing purposes)

wrapped

added in 4.0

(wrapped val)(wrapped val show)(wrapped val show type)(wrapped val show type display)

object to display shell result

wrapped?

added in 4.0

(wrapped? val)

checks that an object is wrapped

xor

macro

added in 3.0

(xor)(xor a)(xor a b)

performs xor comparison

(xor true false) => true

Z

added in 3.0

(Z f)

Z combinator

((Z factorial) 5) => 120