Lits
v1.0.0

Welcome to Lits!


Lits is a Lisp dialect made to work well in a browser or Node environment. It's heavily inspired by Clojure, most of the core functions from Clojure have been ported.

Some outstanding features / shortcommings worth mentioning.

  • All datatypes in Lits are immutable.
  • All functions are pure, unless the built-in function name ends with a !. See
    write!
    or
    rand!
    for example.
  • All datatypes in Lits mapps directly to Javascript's types.
  • No lazy evaluation.
  • No quotes.
  • No macros.
  • No keyword symbols.
    :foo
    is just a shorthand for
    "foo"
    .
  • Dynamic scoping, no lexical scoping
  • 100% test coverage

You can see some examples and find documentation of all built-in function to the left.

For more instruction on how to install and use Lits as a cli or a typescript lib, checkout https://github.com/YouCruit/lits

Happy coding!

Examples


  • Simple Lisp expression
    A super simple example.
    Show in playground
  • Params in use
    Simple example using params.
    Show in playground
  • Phone number formatter
    Pretty prints a US phone number.
    Show in playground
  • Factorial
    A recursive implementation of the factorial function.
    Show in playground
  • Sort
    Sort an array of numbers.
    Show in playground
  • Many arities
    Function with multiple arities.
    Show in playground
  • Translations lib
    A Lits take on i18n.
    Show in playground
  • Is ISO date string
    Check if string is formatted as an ISO date string.
    Show in playground
  • label-from-value
    Find label to corresponding value in array of {label value}-objects.
    Show in playground
  • labels-from-values
    Find labels to corresponding values in array of {label value}-objects.
    Show in playground
count

Returns number of elements in coll.

count coll => number
coll: collection | string
  (count [1 2 3]) => 3  
  (count []) => 0  
  (count (object :a 1)) => 1  
  (count "") => 0  
  (count "Albert") => 6  

Returns value in coll mapped at key.

get coll key default(optional) => any
coll: collection
key: string or integer
default: any
  (get [1 2 3] 1) => 2  
  (get [] 1) => null  
  (get [] 1 "default") => "default"  
  (get (object :a 1) :a) => 1  
  (get (object :a 1) :b) => null  
  (get (object :a 1) :b "default") => "default"  
  (get nil :a) => null  
  (get nil :b "default") => "default"  
get-in

Returns the value in a nested collection, where keys is an array of keys. Returns default if the key is not present. If default is not set, nil is returned.

get-in coll keys default(optional) => any
coll: collection
keys: Array
default: any
  (get-in [[1 2 3] [4 {:a "Kalle"} 6]] [1 1 :a 0]) => "K"  
  (get-in [[1 2 3] [4 {:a "Kalle"} 6]] [1 1 :b 0]) => null  
  (get-in [[1 2 3] [4 {:a "Kalle"} 6]] [1 1 :b 0] "Lisa") => "Lisa"  
contains?

Returns true if collection contains key, otherwise returns false.

contains? coll key => boolean
coll: collection
key: string or number
  (contains? [] 1) => false  
  (contains? [1] 1) => false  
  (contains? [1 2 3] 1) => true  
  (contains? {} :a) => false  
  (contains? {:a 1 :b 2} :a) => true  
has?

Returns true if collection has value, otherwise returns false.

has? coll key => boolean
coll: collection
key: string or number
  (has? [1 2 3] 1) => true  
  (has? [1 2 3] 0) => false  
  (has? {:a 1 :b 2} 1) => true  
  (has? {:a 1 :b 2} 0) => false  
  (has? "Albert" :A) => true  
  (has? "Albert" :a) => false  
has-some?

Returns true if collection has any of the elements in keys, otherwise returns false.

has-some? coll keys => boolean
coll: collection
keys: Seq
  (has-some? [] []) => false  
  (has-some? [1 2 3] []) => false  
  (has-some? [1 2 3] [0]) => false  
  (has-some? [1 2 3] [0 1]) => true  
  (has-some? (object :a 1 :b 2) [0]) => false  
  (has-some? (object :a 1 :b 2) [0 1]) => true  
  (has-some? "Albert" "xyz") => false  
  (has-some? "Albert" "xyzl") => true  
  (has-some? [:a :b :c :d] "xyz") => false  
  (has-some? [:a :b :c :d] "xyzc") => true  
has-every?

Returns true if collection has all of the elements in keys, otherwise returns false.

has-every? coll keys => boolean
coll: collection
keys: Seq
  (has-every? [] []) => true  
  (has-every? [1 2 3] []) => true  
  (has-every? [1 2 3] [0 1]) => false  
  (has-every? [1 2 3] [1 2]) => true  
  (has-every? (object :a 1 :b 2) [0 1]) => false  
  (has-every? (object :a 1 :b 2) [1 2]) => true  
  (has-every? "Albert" "xyz") => false  
  (has-every? "Albert" "treblA") => true  
  (has-every? [:a :b :c :d] "xyz") => false  
  (has-every? [:a :b :c :d] "dcba") => true  
assoc

Sets value on specified element of coll.

assoc coll key value => collection
coll: collection
key: string or number
value: any
  (assoc [1 2 3] 1 "Two") => [1,"Two",3]  
  (assoc [1 2 3] 3 "Four") => [1,2,3,"Four"]  
  (assoc {:a 1 :b 2} :a "One") => {"a":"One","b":2}  
  (assoc {:a 1 :b 2} :c "Three") => {"a":1,"b":2,"c":"Three"}  
assoc-in

Associates a value in a nested Coll, where keys is an array of keys and value is the new value and returns a new nested structure. If any levels do not exist, objects will be created - and the corresponding keys must be of type string.

assoc-in coll keys value => collection
coll: collection
keys: Array
value: any
  (assoc-in {} [:a :b :c] "Albert") => {"a":{"b":{"c":"Albert"}}}  
  (assoc-in [1 2 [1 2 3]] [2 1] "Albert") => [1,2,[1,"Albert",3]]  
  (assoc-in [1 2 {"name" "albert"}] [2 "name" 0] :A) => [1,2,{"name":"Albert"}]  
concat

Concatenates array or object arguments into one collection.

concat value(zero or more) => collection
value: collection
  (concat [1 2] [3 4]) => [1,2,3,4]  
  (concat [] [3 4]) => [3,4]  
  (concat [1 2] []) => [1,2]  
  (concat [1 2] [3 4] [5 6]) => [1,2,3,4,5,6]  
  (concat []) => []  
  (concat {:a 1 :b 2} {:b 1 :c 2}) => {"a":1,"b":1,"c":2}  
  (concat {} {:a 1}) => {"a":1}  
not-empty

Returns null if coll is empty, otherwise coll.

not-empty coll => boolean
coll: collection or string
  (not-empty []) => null  
  (not-empty [1 2 3]) => [1,2,3]  
  (not-empty {}) => null  
  (not-empty {:a 2}) => {"a":2}  
  (not-empty "") => null  
  (not-empty "Albert") => "Albert"  
every?

Returns true if all entries in coll pass the test implemented by finder, otherwise returns false.

every? coll finder => boolean
coll: Coll
finder: function
  (every? string? ["Albert" "Mojir" 160 [1 2]]) => false  
  (every? (fn [x] (> x 10)) [50 100 150 200]) => true  
  (every? number? []) => true  
  (every? number? "") => true  
  (every? number? {}) => true  
  (every? #(even? (second %1)) {:a 2 :b 4}) => true  
  (every? #(even? (second %1)) {:a 2 :b 3}) => false  
not-every?

Returns true if all entries in coll pass the test implemented by finder, otherwise returns false.

not-every? coll finder => boolean
coll: Coll
finder: function
  (not-every? string? ["Albert" "Mojir" 160 [1 2]]) => true  
  (not-every? (fn [x] (> x 10)) [50 100 150 200]) => false  
  (not-every? number? []) => false  
  (not-every? number? "") => false  
  (not-every? number? {}) => false  
  (not-every? #(even? (second %1)) {:a 2 :b 4}) => false  
  (not-every? #(even? (second %1)) {:a 2 :b 3}) => true  

Returns true if any entry in coll pass the test implemented by finder, otherwise returns false.

any? coll finder => boolean
coll: Coll
finder: function
  (any? string? ["Albert" "Mojir" 160 [1 2]]) => true  
  (any? (fn [x] (> x 10)) [50 100 150 200]) => true  
  (any? number? []) => false  
  (any? number? "") => false  
  (any? number? {}) => false  
  (any? #(even? (second %1)) {:a 2 :b 3}) => true  
  (any? #(even? (second %1)) {:a 1 :b 3}) => false  
not-any?

Returns false if any entry in coll pass the test implemented by finder, otherwise returns true.

not-any? coll finder => boolean
coll: Coll
finder: function
  (not-any? string? ["Albert" "Mojir" 160 [1 2]]) => false  
  (not-any? (fn [x] (> x 10)) [50 100 150 200]) => false  
  (not-any? number? []) => true  
  (not-any? number? "") => true  
  (not-any? number? {}) => true  
  (not-any? #(even? (second %1)) {:a 2 :b 3}) => false  
  (not-any? #(even? (second %1)) {:a 1 :b 3}) => true  
update

Updates a value in collection, where key is a key and fn is a function that will take the old value and any supplied args and return the new value, and returns a new collection. If the key does not exist, nil is passed as the old value.

update coll key fn args(zero or more) => Coll
coll: Coll
key: string | number
fn: function
args: Any
  (def x {:a 1 :b 2}) (update x :a inc) => {"a":2,"b":2}  
  (def x {:a 1 :b 2}) (update x :c (fn [val] (if (nil? val) 0 (inc val)))) => {"a":1,"b":2,"c":0}  
update-in

'Updates' a value in coll, where keys is an array of keys (string or number) and fn is a function that will take the old value and any supplied args and return the new value, and returns a new Coll. If any levels do not exist, objects will be created - and the corresponding keys must be of type string.

update-in coll keys fn args(zero or more) => Coll
coll: Coll
keys: Arr
fn: function
args: Any
  (update-in {:a [1 2 3]} [:a 1] (fn [val] (when (nil? val) 0))) => {"a":[1,null,3]}  
  (update-in {:a [1 "Albert" 3]} [:a 1 0] (fn [val] (if (nil? val) "?" "!"))) => {"a":[1,"!lbert",3]}  
array

Makes new array from values.

array values => array
values: array
  (array 1 2 3) => [1,2,3]  
  (array (array nil false true)) => [[null,false,true]]  
  [] => []  
  [1 2 3] => [1,2,3]  
  [[nil false true]] => [[null,false,true]]  
  [] => []  
  ([1 2 3] 1) => 2  
  ([1 2 3 4 5 6 7 8 9] 3) => 4  
range

Create an array with a range of numbers. If only one argument: 0...a, otherwise: a...b. step defaults to 1.

range a length(optional) length(optional) => array
a: number
length: number
length: number
  (range 4) => [0,1,2,3]  
  (range 1 4) => [1,2,3]  
  (range 0.4 4.9) => [0.4,1.4,2.4,3.4,4.4]  
  (range 0.25 1 0.25) => [0.25,0.5,0.75]  
repeat

Returns an array with value repeated count times.

repeat count value => array
count: non negative integer
value: any
  (repeat 3 10) => [10,10,10]  
  (repeat 0 10) => []  
  (repeat 5 "Albert") => ["Albert","Albert","Albert","Albert","Albert"]  
flatten

Takes a nested array and return a flat array. If input isn't an array, an empty array is returned.

flatten input => array
input: Array
  (flatten [1 2 [3 4] 5]) => [1,2,3,4,5]  
  (flatten [1 2 [3 [4 [5]]] 6]) => [1,2,3,4,5,6]  
  (flatten 12) => []  
mapcat

Returns the result of applying concat to the result of applying map to mapper and arrays.

mapcat mapper arrays(one or many) => Array
mapper: function
arrays: Array
  (mapcat reverse [[3 2 1 0] [6 5 4] [9 8 7]]) => [0,1,2,3,4,5,6,7,8,9]  
  (mapcat reverse [[3 2 1 0] [6 [5] 4] [9 8 7]]) => [0,1,2,3,4,[5],6,7,8,9]  
  (defn foo [n] [(- n 1) n (+ n 1)]) (mapcat foo [1 2 3]) => [0,1,2,1,2,3,2,3,4]  
  (mapcat #(remove even? %1) [[1 2] [2 2] [2 3]]) => [1,3]  

Accesses element index of input. Accessing out-of-bounds indices returns notFound or nil.

nth input index notFound(optional) => any
input: string | array | nil
index: integer
notFound: any
  (nth [1 2 3] 1) => 2  
  (nth [1 2 3] 3) => null  
  (nth [1 2 3] -1) => null  
  (nth [1 2 3] 3 99) => 99  
  (nth "A string" 1) => " "  
  (nth "A string" 3) => "t"  
  (nth "A string" -3) => null  
  (nth "A string" 30 :X) => "X"  
  (nth nil 1) => null  
  (nth nil 1 "Default value") => "Default value"  
push

Pushes values to the end of array.

push array values(one or more) => array
array: array
values: array
  (push [1 2 3] 4) => [1,2,3,4]  
  (push [1 2 3] 4 5 6) => [1,2,3,4,5,6]  
  (def l [1 2 3]) (push l 4) l => [1,2,3]  

Removes and returns then last item of array. If array is empty, nil is returned.

pop array value => array
array: array
value: any
  (pop [1 2 3]) => [1,2]  
  (pop []) => []  
unshift

Inserts values at the beginning of array.

unshift array values(one or more) => array
array: array
values: array
  (unshift [1 2 3] 4) => [4,1,2,3]  
  (unshift [1 2 3] 4 5 6) => [4,5,6,1,2,3]  
  (def l [1 2 3]) (unshift l 4) l => [1,2,3]  
shift

Removes and returns the first item of array. If array is empty, nil is returned.

shift array value => array
array: array
value: any
  (shift [1 2 3]) => [2,3]  
  (shift []) => []  
slice

Returns a shallow copy of a portion of array into a new array selected from index start (inclusive) to index end (exclusive). If start is not provided it defaults to 0. If end is not provided, the rest of the array will be copied.

slice array start(optional) end(optional) => array
array: array
start: number
end: number
  (slice [1 2 3 4 5] 2 4) => [3,4]  
  (slice [1 2 3 4 5] 2) => [3,4,5]  
reductions

Returns an array of the intermediate values of the reduction (see reduce) of seq by reducer.

reductions array reducer startValue => array
array: array
reducer: function
startValue: any
  (reductions + [1 2 3]) => [1,3,6]  
  (reductions + 0 [1 2 3]) => [0,1,3,6]  
  (reductions + 0 []) => [0]  
  (reductions (fn [result value] (+ result (if (even? value) value 0))) 0 [1 2 3 4 5 6 7 8 9]) => [0,0,2,2,6,6,12,12,20,20]  
reduce

Runs reducer function on each element of the seq, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the seq is a single value.

reduce reducer startValue(optional) seq => sequence
reducer: function
startValue: any
seq: Seq
  (reduce + [1 2 3]) => 6  
  (reduce + 0 [1 2 3]) => 6  
  (reduce + 0 []) => 0  
  (reduce (fn [result value] (+ result (if (even? value) value 0))) 0 [1 2 3 4 5 6 7 8 9]) => 20  
reduce-right

Runs reducer function on each element of the seq (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the seq is a single value.

reduce-right reducer startValue seq => sequence
reducer: function
startValue: any
seq: Seq
  (reduce-right str [:A :B :C] "") => ["A","B","C"]  

Creates a new array populated with the results of calling mapper on every elements in the calling sequences.

map mapper sequence(one or many) => array
mapper: function
sequence: Seq
  (map str ["Albert" "Mojir" 42]) => ["Albert","Mojir","42"]  
  (map str []) => []  
  (map + [1 2 3] [1 2 3]) => [2,4,6]  
  (map max [2 6 3] [2 4 7] [1 6 2]) => [2,6,7]  
filter

Creates a new array with all elements that pass the test implemented by filter.

filter array filter => array
array: array
filter: function
  (filter string? ["Albert" "Mojir" 160 [1 2]]) => ["Albert","Mojir"]  
  (filter (fn [x] (> x 10)) [5 10 15 20]) => [15,20]  
position

Returns the index of the first elements that pass the test implemented by finder. If no element was found, nil is returned.

position array finder => number
array: array
finder: function
  (position string? ["Albert" "Mojir" 160 [1 2]]) => 0  
  (position (fn [x] (> x 10)) [5 10 15 20]) => 2  
  (position (fn [x] (> x 100)) [5 10 15 20]) => null  
index-of

Returns the index of value in array. If element is not present in array nil is returned.

index-of array value => number
array: array
value: any
  (index-of ["Albert" "Mojir" 160 [1 2]] "Mojir") => 1  
  (index-of [5 10 15 20] 15) => 2  
  (index-of [5 10 15 20] 1) => null  

Returns the first elements that pass the test implemented by finder. I no element was found, nil is returned.

some array finder => array
array: array
finder: function
  (some string? ["Albert" "Mojir" 160 [1 2]]) => "Albert"  
  (some (fn [x] (> x 10)) [5 10 15 20]) => 15  
  (some (fn [x] (> x 10)) [1 2 3 4]) => null  
  (some (fn [x] (> x 10)) []) => null  
reverse

If input is an array, creates a new array with the elements from input in reversed order. If input is a string, returns new reversed string.

reverse input => array or string
input: input or string
  (reverse ["Albert" "Mojir" 160 [1 2]]) => [[1,2],160,"Mojir","Albert"]  
  (reverse []) => []  
  (reverse "Albert") => "treblA"  
first

Returns the first element of array. If array is empty, nil is returned.

first array => any
array: array
  (first ["Albert" "Mojir" 160 [1 2]]) => "Albert"  
  (first []) => null  
second

Returns the second element of array. If array has less than two elements, nil is returned.

second array => any
array: array
  (second ["Albert" "Mojir" 160 [1 2]]) => "Mojir"  
  (second [1]) => null  
  (second []) => null  

Returns the last element of array. If array is empty, nil is returned.

last array => any
array: array
  (last ["Albert" "Mojir" 160 [1 2]]) => [1,2]  
  (last [1 2]) => 2  
  (last [1]) => 1  
  (last []) => null  

If input is an array, returns a new array with all but the first element from input. If input has less than two elements, an empty array is returned. For string input returns all but the first characters in input.

rest input => array | string
input: array | string
  (rest ["Albert" "Mojir" 160 [1 2]]) => ["Mojir",160,[1,2]]  
  (rest ["Albert"]) => []  
  (rest []) => []  
  (rest "Albert") => "lbert"  
  (rest :A) => ""  
  (rest "") => ""  
nthrest

If input is an array, returns a new array with all but the first count elements from input. For string input returns all but the first count characters in input.

nthrest array => array
array: array
  (nthrest ["Albert" "Mojir" 160 [1 2]] 2) => [160,[1,2]]  
  (nthrest "Albert" 3) => "ert"  
  (nthrest "Albert" 6) => ""  
  (nthrest [] 0) => []  
  (nthrest "" 0) => ""  
nthnext

If input is an array, returns a new array with all but the first count elements from input. If input has less or equal than count elements, nil returned. For string input returns all but the first count characters in input. If length of string input is less or equal than count, nil is returned.

nthnext array => array
array: array
  (nthnext ["Albert" "Mojir" 160 [1 2]] 2) => [160,[1,2]]  
  (nthnext "Albert" 3) => "ert"  
  (nthnext "Albert" 6) => null  
  (nthnext [] 0) => null  
  (nthnext "" 0) => null  

Constructs a new array with element as first element and rest as the rest.

cons array => array
array: array
  (cons "Hi" ["Albert" "Mojir" 160 [1 2]]) => ["Hi","Albert","Mojir",160,[1,2]]  
  (cons "Hi" []) => ["Hi"]  

Constructs a new array/string with the count first elements from input.

take count input => array | string
count: integer
input: array | string
  (take 3 [1 2 3 4 5]) => [1,2,3]  
  (take 0 [1 2 3 4 5]) => []  
  (take 2 "Albert") => "Al"  
  (take 50 "Albert") => "Albert"  
take-last

Constructs a new array with the count last elements from array.

take-last array count => array
array: array
count: integer
  (take-last 3 [1 2 3 4 5]) => [3,4,5]  
  (take-last 0 [1 2 3 4 5]) => []  
take-while

Returns the members of array in order, stopping before the first one for which predicate returns a falsy value.

take-while predicate array => array
predicate: function
array: array
  (take-while (fn [x] (< x 3)) [1 2 3 2 1]) => [1,2]  
  (take-while (fn [x] (> x 3)) [1 2 3 2 1]) => []  

Constructs a new array/string with the count first elements dropped from input.

drop count input => array | string
count: integer
input: array | string
  (drop 3 [1 2 3 4 5]) => [4,5]  
  (drop 0 [1 2 3 4 5]) => [1,2,3,4,5]  
  (drop 2 "Albert") => "bert"  
  (drop 50 "Albert") => ""  
drop-last

Constructs a new array with the count last elements dropped from array.

drop-last count array => array
count: integer
array: array
  (drop-last 3 [1 2 3 4 5]) => [1,2]  
  (drop-last 0 [1 2 3 4 5]) => [1,2,3,4,5]  
drop-while

Returns the members of array in order, skipping the fist elements for witch the predicate returns a truethy value.

drop-while predicate array => array
predicate: function
array: array
  (drop-while (fn [x] (< x 3)) [1 2 3 2 1]) => [3,2,1]  
  (drop-while (fn [x] (> x 3)) [1 2 3 2 1]) => [1,2,3,2,1]  

Returns a new Seq with the elements from seq sorted according to comparer. If no comparer is supplied, builtin compare will be used.

sort comparer(optional) seq => array
comparer: function
seq: Seq
  (sort [3 1 2]) => [1,2,3]  
  (sort (fn [a b] (cond (< a b) -1 (> a b) 1 true -1)) [3 1 2]) => [1,2,3]  
  (sort (fn [a b] (cond (> a b) -1 (< a b) 1 true -1)) [3 1 2]) => [3,2,1]  
sort-by

Returns a sorted sequence of the items in seq, where the sort order is determined by comparing (keyfn item). If no comparer is supplied, uses builtin compare.

sort-by keyfn comparer(optional) seq => array
keyfn: function
comparer: function
seq: Seq
  (sort-by count ["Albert" "Mojir" "Nina"]) => ["Nina","Mojir","Albert"]  
  (sort-by lower-case "Albert") => "Abelrt"  
join

Returns a new string by concatenating all of the elements in array, separated by delimiter.

join array delimiter => string
array: array of strings
delimiter: string
  (join ["Albert" "Mojir"] " ") => "Albert Mojir"  
  (join (map number-to-string [0 1 2 3 4 5 6 7 8 9]) ", ") => "0, 1, 2, 3, 4, 5, 6, 7, 8, 9"  
random-sample!

Returns an array. Each element from array has the probability prob to be included in the result.

random-sample! prob(between 0 and 1) array => array
prob: number
array: array
  (random-sample! 0.5 [1 2 3 4 5 6 7 8 9 10]) => [8]  
  (random-sample! 0.5 "Albert") => "Albt"  
rand-nth!

Returns a random element from seq. Returns nil if seq is empty.

rand-nth! seq => any
seq: seq
  (rand-nth! [1 2 3 4 5 6 7 8 9 10]) => 4  
  (rand-nth! "Albert") => "l"  
  (rand-nth! []) => null  
shuffle!

Returns a shuffled copy of input.

shuffle! input => Seq
input: Seq
  (shuffle! [1 2 3 4 5 6 7 8 9 10]) => [3,9,10,2,4,1,5,7,6,8]  
  (shuffle! "Albert Mojir") => "MoitA lbrerj"  
  (shuffle! [1 2]) => [2,1]  
  (shuffle! [1]) => [1]  
  (shuffle! []) => []  
distinct

Returns a copy of input with no duplicates.

distinct input => Seq
input: Seq
  (distinct [1 2 3 1 3 5]) => [1,2,3,5]  
  (distinct "Albert Mojir") => "Albert Moji"  
  (distinct []) => []  
  (distinct "") => ""  
remove

Returns a new sequence of items in input for witch (pred item) returns a falsy value.

remove pred input => Seq
pred: Function
input: Seq
  (remove even? [1 2 3 1 3 5]) => [1,3,1,3,5]  
  (remove #(has? "aoueiyAOUEIY" %1) "Albert Mojir") => "lbrt Mjr"  
remove-at

Returns a new sequence of all items in input except item at index.

remove-at index input => Seq
index: number
input: Seq
  (remove-at 0 [1 2 3 1 3 5]) => [2,3,1,3,5]  
  (remove-at -1 [1 2 3 1 3 5]) => [1,2,3,1,3,5]  
  (remove-at 6 "Albert Mojir") => "AlbertMojir"  
split-at

Returns a new array/string of [(take pos input) (drop pos input)].

split-at pos input => Seq
pos: number
input: Seq
  (split-at 2 [1 2 3 4 5]) => [[1,2],[3,4,5]]  
  (split-at 2 "Albert") => ["Al","bert"]  
split-with

Returns a new array/string of [(take-while pos input) (drop-while pos input)].

split-with pos input => Seq
pos: number
input: Seq
  (split-with #(> %1 3) [1 2 3 4 5]) => [[],[1,2,3,4,5]]  
  (split-with #(<= %1 :Z) "Albert") => ["A","lbert"]  
frequencies

Returns an object from distinct items in seq to the number of times they appear. Note that all items in seq must be valid object keys i.e. strings.

frequencies input => Obj
input: Seq
  (frequencies ["Albert" "Mojir" "Nina" "Mojir"]) => {"Albert":1,"Mojir":2,"Nina":1}  
  (frequencies "Pneumonoultramicroscopicsilicovolcanoconiosis") => {"P":1,"n":4,"e":1,"u":2,"m":2,"o":9,"l":3,"t":1,"r":2,"a":2,"i":6,"c":6,"s":4,"p":1,"v":1}  
group-by

Returns an object of the elements of seq keyed by the result of fn on each element. The value at each key will be an array of the corresponding elements.

group-by fn input => Obj
fn: Function
input: Seq
  (group-by "name" [{"name" "Albert"} {"name" "Albert"} {"name" "Mojir"}]) => {"Albert":[{"name":"Albert"},{"name":"Albert"}],"Mojir":[{"name":"Mojir"}]}  
  (group-by (fn [char] (if (has? "aoueiAOUEI" char) "vowel" "other")) "Albert Mojir") => {"vowel":["A","e","o","i"],"other":["l","b","r","t"," ","M","j","r"]}  
partition

Returns an array of sequences of n items each, at offsets step apart. If step is not supplied, defaults to n. If a pad array is supplied, use its elements as necessary to complete last partition upto n items. In case there are not enough padding elements, return a partition with less than n items.

partition n step(optional) pad(optional) seq => Seq
n: number
step: number
pad: Arr
seq: Seq
  (partition 4 (range 20)) => [[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15],[16,17,18,19]]  
  (partition 4 (range 22)) => [[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15],[16,17,18,19]]  
  (partition 4 6 (range 20)) => [[0,1,2,3],[6,7,8,9],[12,13,14,15]]  
  (partition 4 3 (range 20)) => [[0,1,2,3],[3,4,5,6],[6,7,8,9],[9,10,11,12],[12,13,14,15],[15,16,17,18]]  
  (partition 3 6 [:a] (range 20)) => [[0,1,2],[6,7,8],[12,13,14],[18,19,"a"]]  
  (partition 4 6 [:a] (range 20)) => [[0,1,2,3],[6,7,8,9],[12,13,14,15],[18,19,"a"]]  
  (partition 4 6 [:a :b :c :d] (range 20)) => [[0,1,2,3],[6,7,8,9],[12,13,14,15],[18,19,"a","b"]]  
  (partition 3 1 [:a :b :c :d :e :f]) => [["a","b","c"],["b","c","d"],["c","d","e"],["d","e","f"]]  
  (partition 10 [1 2 3 4]) => []  
  (partition 10 10 [1 2 3 4]) => []  
  (partition 10 10 [] [1 2 3 4]) => [[1,2,3,4]]  
  (partition 10 10 nil [1 2 3 4]) => [[1,2,3,4]]  
  (partition 5 "superfragilistic") => ["super","fragi","listi"]  
  (partition 5 5 nil "superfragilistic") => ["super","fragi","listi","c"]  
  (def foo [5 6 7 8]) (partition 2 1 foo foo) => [[5,6],[6,7],[7,8],[8,5]]  
partition-all

Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.

partition-all n step(optional) seq => Seq
n: number
step: number
seq: Seq
  (partition-all 4 [0 1 2 3 4 5 6 7 8 9]) => [[0,1,2,3],[4,5,6,7],[8,9]]  
  (partition 4 [0 1 2 3 4 5 6 7 8 9]) => [[0,1,2,3],[4,5,6,7]]  
  (partition-all 2 4 [0 1 2 3 4 5 6 7 8 9]) => [[0,1],[4,5],[8,9]]  
partition-by

Applies fn to each value in seq, splitting it each time fn returns a new value. Returns an array of sequences.

partition-by fn seq => Seq
fn: function
seq: Seq
  (partition-by #(= 3 %1) [1 2 3 4 5]) => [[1,2],[3],[4,5]]  
  (partition-by odd? [1 1 1 2 2 3 3]) => [[1,1,1],[2,2],[3,3]]  
  (partition-by identity "Leeeeeerrroyyy") => ["L","eeeeee","rrr","o","yyy"]  

Computes sum of numbers.

+ numbers(zero or more) => number
numbers: number[]
  (+) => 0  
  (+ 1) => 1  
  (+ 2 4) => 6  
  (+ 1 2 3 4) => 10  
  (+ (+ 2 3) (+ 5 6)) => 16  

Computes difference between first value and sum of the rest. When called with only one argument, it does negation.

- numbers(zero or more) => number
numbers: number[]
  (-) => 0  
  (- 1) => -1  
  (- 2 4) => -2  
  (- 4 3 2 1) => -2  

Computes product of numbers.

* numbers(zero or more) => number
numbers: number[]
  (*) => 1  
  (* 2) => 2  
  (* 2 4) => 8  
  (* 1 2 3 4) => 24  

Computes division or reciprocal. When called with one argument it computes reciprocal. When called with two or more arguments it does compute division of the first by the all remaining numbers.

/ numbers(zero or more) => number
numbers: number[]
  (/) => 1  
  (/ 2) => 0.5  
  (/ 2 4) => 0.5  
  (/ 4 3 2 1) => 0.6666666666666666  

Modulus of dividend and divisor. Truncates toward negative infinity.

mod dividend divisor => number
dividend: number
divisor: number
  (mod 5 3) => 2  
  (mod 5.2 3.1) => 2.1  
  (mod -5 3) => 1  
  (mod 5 -3) => -1  
  (mod -5 -3) => -2  

Remainder of dividing dividend and divisor.

rem dividend divisor => number
dividend: number
divisor: number
  (rem 5 3) => 2  
  (rem 5.2 3.1) => 2.1  
  (rem -5 3) => -2  
  (rem 5 -3) => 2  
  (rem -5 -3) => -2  

Quotient of dividing dividend and divisor.

quot dividend divisor => number
dividend: number
divisor: number
  (quot 5 3) => 1  
  (quot 5.2 3.1) => 1  
  (quot -5 3) => -1  
  (quot 5 -3) => -1  
  (quot -5 -3) => 1  

Adds one to number.

inc number => number
number: number
  (inc 0) => 1  
  (inc 1) => 2  
  (inc 100.1) => 101.1  

Subtracts one from number.

dec number => number
number: number
  (dec 0) => -1  
  (dec 1) => 0  
  (dec 100.1) => 99.1  
sqrt

Computes square root of number.

sqrt number => number
number: number
  (sqrt 0) => 0  
  (sqrt 9) => 3  
  (sqrt 2) => 1.4142135623730951  
cbrt

Computes cube root of number.

cbrt number => number
number: number
  (cbrt 0) => 0  
  (cbrt 27) => 3  
  (cbrt 2) => 1.2599210498948732  
  (cbrt 1) => 1  
pow

Computes returns base-number raised to the power-number.

pow base-number power-number => number
base-number: number
power-number: number
  (pow 2 3) => 8  
  (pow 2 0) => 1  
  (pow 2 -3) => 0.125  
  (pow -2 3) => -8  
  (pow -2 -3) => -0.125  
exp

Computes e rasied to the power-number.

exp power-number => number
power-number: number
  (exp 3) => 20.085536923187668  
  (exp 0) => 1  
  (exp -3) => 0.049787068367863944  
  (exp 3) => 20.085536923187668  
round

Returns rounded number. If decimals is provided it return a number with that many decimals.

round number decimals(optional) => number
number: number
decimals: integer
  (round 2) => 2  
  (round 2.49) => 2  
  (round 2.5) => 3  
  (round -2.49) => -2  
  (round -2.5) => -2  
  (round -2.501) => -3  
  (round 1.23456789 4) => 1.2346  
trunc

Returns the integer part of number by removing any fractional digits.

trunc number => integer
number: number
  (trunc 2) => 2  
  (trunc 2.49) => 2  
  (trunc 2.5) => 2  
  (trunc -2.49) => -2  
  (trunc -2.5) => -2  
  (trunc -2.501) => -2  
floor

Returns the largest integer less than or equal to number.

floor number => integer
number: number
  (floor 2) => 2  
  (floor 2.49) => 2  
  (floor 2.5) => 2  
  (floor -2.49) => -3  
  (floor -2.5) => -3  
  (floor -2.501) => -3  
ceil

Returns the smallest integer larger than or equal to number.

ceil number => integer
number: number
  (ceil 2) => 2  
  (ceil 2.49) => 3  
  (ceil 2.5) => 3  
  (ceil -2.49) => -2  
  (ceil -2.5) => -2  
  (ceil -2.501) => -2  

Returns the smallest number of the arguments.

min numbers((one or many)) => number
numbers: number[]
  (min 2 0 1) => 0  
  (min 2 -1 1) => -1  
  (min 2.5) => 2.5  

Returns the largest number of the arguments.

max numbers((one or many)) => number
numbers: number[]
  (max 2 0 1) => 2  
  (max 2 -1 1) => 2  
  (max 2.5) => 2.5  
abs

Returns the absolute value of number.

abs number => number
number: number
  (abs -2.3) => 2.3  
  (abs 0) => 0  
  (abs 2.5) => 2.5  
sign

Returns 1 if number > 0, -1 if number < 0, 0 if number = 0 or -0 if number = -0.

sign number => number
number: number
  (sign -2.3) => -1  
  (sign -0) => 0  
  (sign 0) => 0  
  (sign 12312) => 1  
positive-infinity

Returns a number representing positive positive-infinity.

positive-infinity => number
  (positive-infinity) => null  
negative-infinity

Returns a number representing negative infinity.

negative-infinity => number
  (negative-infinity) => null  
max-safe-integer

Returns a number representing the maximum safe integer.

max-safe-integer => number
  (max-safe-integer) => 9007199254740991  
min-safe-integer

Returns a number representing the minimum safe integer.

min-safe-integer => number
  (min-safe-integer) => -9007199254740991  
max-value

Returns a number representing the maximum numeric value.

max-value => number
  (max-value) => 1.7976931348623157e+308  
min-value

Returns a number representing the smallest positive numeric value.

min-value => number
  (min-value) => 5e-324  
epsilon

Returns a number representing the difference between 1 and the smallest floating point number greater than 1.

epsilon => number
  (epsilon) => 2.220446049250313e-16  

Returns a number representing Not-A-Number.

nan => number
  (nan) => null  
e

Returns Euler's number, the base of natural logarithms, e.

e => number
  (e) => 2.718281828459045  
pi

Returns Pi, the ratio of the circumference of a circle to its diameter.

pi => number
  (pi) => 3.141592653589793  
log

Returns the natural logarithm (base e) of number.

log number => number
number: number
  (log 0.01) => -4.605170185988091  
  (log (exp 12)) => 12  
  (log 2.5) => 0.9162907318741551  
log2

Returns the base 2 logarithm of a number.

log2 number => number
number: number
  (log2 0.01) => -6.643856189774724  
  (log2 (pow 2 12)) => 12  
  (log2 2.5) => 1.3219280948873624  
log10

Returns the base 2 logarithm of a number.

log10 number => number
number: number
  (log10 0.01) => -2  
  (log10 (pow 10 12)) => 12  
  (log10 2.5) => 0.3979400086720376  
rand!

Returns a semi random number between 0 (inclusive) and number (default 1) (exclusive).

rand! number(optional) => number
number: positive number
  (rand! 1) => 0.3982850796273931  
  (rand! 0.01) => 0.002873506564909625  
  (rand! 2.5) => 1.6869433233293645  
rand-int!

Returns a semi random integer between 0 (inclusive) and number (exclusive).

rand-int! number(optional) => number
number: positive number
  (rand-int! 1) => 0  
  (rand-int! 10.12) => 2  
  (rand-int! 123) => 91  
sin

Returns the sine of angle. angle must be specified in radians.

sin angle => number
angle: number
  (sin 0) => 0  
  (sin 1) => 0.8414709848078965  
  (sin (pi)) => 1.2246467991473532e-16  
  (sin -0.5) => -0.479425538604203  
cos

Returns the cosine of angle. angle must be specified in radians.

cos angle => number
angle: number
  (cos 0) => 1  
  (cos 1) => 0.5403023058681398  
  (cos (pi)) => -1  
  (cos -0.5) => 0.8775825618903728  
tan

Returns the tangent of angle. angle must be specified in radians.

tan angle => number
angle: number
  (tan 0) => 0  
  (tan 1) => 1.5574077246549023  
  (tan (pi)) => -1.2246467991473532e-16  
  (tan -0.5) => -0.5463024898437905  
asin

Returns the arcsine (in radians) of value.

asin value => number
value: number
  (asin 0) => 0  
  (asin 1) => 1.5707963267948966  
  (asin -0.5) => -0.5235987755982989  
acos

Returns the arccosine (in radians) of value.

acos value => number
value: number
  (acos 0) => 1.5707963267948966  
  (acos 1) => 0  
  (acos -0.5) => 2.0943951023931957  
atan

Returns the arctangent (in radians) of value.

atan value => number
value: number
  (atan 0) => 0  
  (atan 1) => 0.7853981633974483  
  (atan -0.5) => -0.4636476090008061  
sinh

Returns the hyperbolic sine of value.

sinh value => number
value: number
  (sinh 0) => 0  
  (sinh 1) => 1.1752011936438014  
  (sinh -0.5) => -0.5210953054937474  
cosh

Returns the hyperbolic cosine of value.

cosh value => number
value: number
  (cosh 0) => 1  
  (cosh 1) => 1.5430806348152437  
  (cosh -0.5) => 1.1276259652063807  
tanh

Returns the hyperbolic tangent of value.

tanh value => number
value: number
  (tanh 0) => 0  
  (tanh 1) => 0.7615941559557649  
  (tanh -0.5) => -0.46211715726000974  
  (tanh 50) => 1  
asinh

Returns the hyperbolic arcsine of value.

asinh value => number
value: number
  (asinh 0) => 0  
  (asinh 0.9) => 0.8088669356527824  
  (asinh -0.5) => -0.48121182505960347  
acosh

Returns the hyperbolic arccosine of value.

acosh value => number
value: number
  (acosh 1) => 0  
  (acosh 2) => 1.3169578969248166  
  (acosh 100) => 5.298292365610484  
atanh

Returns the hyperbolic arctangent of value.

atanh value => number
value: number
  (atanh 0) => 0  
  (atanh 0.9) => 1.4722194895832204  
  (atanh -0.5) => -0.5493061443340548  
apply

Call supplied function with specified arguments.

apply fn args => boolean
fn: function
args: array
  (apply + [1 2 3]) => 6  
  (apply (fn [x y] (sqrt (+ (* x x) (* y y)))) [3 4]) => 5  
identity

Returns value.

identity value => any
value: any
  (identity 1) => 1  
  (identity "Albert") => "Albert"  
  (identity {:a 1}) => {"a":1}  
  (identity nil) => null  
partial

Takes a function fn and fewer (or equal) than the normal arguments to fn, and returns a function that takes a variable number of additional args. When called, the returned function calls f with args + additional args.

partial fn args(zero or more) => function
fn: function
args: any
  (partial + 100) => <function λ>  
  (def addHundred (partial + 100)) (addHundred 10) => 110  

Takes a set of functions and returns a fn that is the composition of those. The returned functions takes a variable number of arguments, applies the rightmost function to the args, the next function (right-to-left) to the result, etc.

comp fn(zero or more) fns(optional) => function
fn: function
fns: function[]
  (def negative-quotient (comp - /)) (negative-quotient 9 3) => -3  
  (#((apply comp first (repeat %2 rest)) %1) [1 2 3 4 5 6 7] 3) => 4  
  (def x {"bar" {"foo" 42}}) ((comp "foo" "bar") x) => 42  
constantly

Returns a function that takes any number of arguments and returns value.

constantly value => function
value: any
  (def always-true (constantly true)) (always-true 9 3) => true  
  (#((apply constantly first (repeat %2 rest)) %1) [1 2 3 4 5 6 7] 3) => <function first>  

Takes variable number of functions and returns a function that is the juxtaposition of those functions. The returned function takes a variable number of args, and returns a vector containing the result of applying each function to the args (left-to-right).

juxt functions(one or more) => Function
functions: Function
  ((juxt + * min max) 3 4 6) => [13,72,3,6]  
  ((juxt :a :b) {:a 1, :b 2, :c 3, :d 4}) => [1,2]  
  (apply (juxt + * min max) (range 1 11)) => [55,3628800,1,10]  
complement

Takes a function and returns a new function that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.

complement function => Function
function: Function
  ((complement >) 1 3) => true  
  ((complement <) 1 3) => false  
  ((complement +) 1 3) => false  
  ((complement +) 0 0) => true  
every-pred

Takes a number of predicates and returns a function that returns true if all of the predicates return a truthy true value against all of its arguments, else it returns false.

every-pred predicates(one or more) => Function
predicates: Function
  ((every-pred string? #(> (count %1) 3)) "Albert" "Mojir") => true  
  ((every-pred string? #(> (count %1) 3)) "Albert" :M) => false  
  ((every-pred string? #(> (count %1) 3)) "Albert" [1 2 3]) => false  
some-pred

Takes a number of predicates and returns a function that returns true if at least one of the predicates return a truthy true value against at least one of its arguments, else it returns false.

some-pred predicates(one or more) => Function
predicates: Function
  ((some-pred string? #(> (count %1) 3)) "Albert" "Mojir") => true  
  ((some-pred string? #(> (count %1) 3)) :A :M) => true  
  ((some-pred string? #(> (count %1) 3)) :A [1 2 3]) => true  
  ((some-pred string? #(> (count %1) 3)) [1 2 3] [2]) => false  

Takes a function fn, and returns a function that calls fn, replacing a nil argument to fn with the corresponding param.

fnil fn param(one or more) => Function
fn: Function
param: Any
  ((fnil + 1 2) 0 0) => 0  
  ((fnil + 1 2) nil 0) => 1  
  ((fnil + 1 2) 0 nil) => 2  
  ((fnil + 1 2) nil nil) => 3  
  ((fnil + 1 2) nil nil 3 4) => 10  

Result is true if no two values are equal to each other, otherwise result is false. Note that only two argument version result is negation of = function, that is (not= a b) is same as (not (= a b)).

not= values => boolean
values: array
  (not= 3) => true  
  (not= 3 2) => true  
  (not= :3 3) => true  
  (not= 3 3 2) => false  
  (not= :3 :2 :1 :0) => true  
  (not= 0 -0) => false  

Compares values according to 'equal' predicate. Result is true if every specified value is equal to each other, otherwise result is false.

= values => boolean
values: array
  (= 1 1) => true  
  (= 1.01 1) => false  
  (= :1 1) => false  
  (= :2 :2 :2 :2) => true  
  (= 2 2 1 2) => false  

Compares values according to 'less than' predicate. Each (overlapping) pair of the values is compared by it. The result is true if all compared pairs satisfy comparison.

< values(one or many) => boolean
values: any
  (< 0 1) => true  
  (< 1 1.01) => true  
  (< 1 1) => false  
  (< 1 2 2 3) => false  
  (< :a :b) => true  
  (< [9] [1 2]) => true  

Compares values according to 'greater than' predicate. Each (overlapping) pair of the values is compared by it. The result is true if all compared pairs satisfy comparison.

> values(one or many) => boolean
values: any
  (> 1 0) => true  
  (> 1.01 1) => true  
  (> 1 1) => false  
  (> 4 3 2 1) => true  
  (> 3 2 2 1) => false  

Compares values according to 'less than or equal' predicate. Each (overlapping) pair of the values is compared by it. The result is true if all compared pairs satisfy comparison.

<= values(one or many) => boolean
values: any
  (<= 0 1) => true  
  (<= 1 1.01) => true  
  (<= 1 1) => true  
  (<= 1 2 3 4) => true  
  (<= 1 2 2 3) => true  

Compares values according to 'greater than or equal' predicate. Each (overlapping) pair of the values is compared by it. The result is true if all compared pairs satisfy comparison.

>= values(one or many) => boolean
values: any
  (>= 1 0) => true  
  (>= 1.01 1) => true  
  (>= 1 1) => true  
  (>= 4 3 2 1) => true  
  (>= 3 2 2 1) => true  

Computes logical negation. Note that any other value than false, 0, nil and '' is considered as true.

not value => boolean
value: any
  (not 3) => false  
  (not true) => false  
  (not "A string") => false  
  (not 0) => true  
  (not false) => true  
  (not nil) => true  
  (not "") => true  
write!

It console.log the values and then returns the last element of the values array. If called with no arguments nil is returned.

write! values => value
values: array
  (write! "A string") => "A string"  
  (write! 100 "items") => "items"  
  (write! (object :a 10)) => {"a":10}  
  (write! [:a :b :c]) => ["a","b","c"]  
  (write! #"^start") => {"__REGEXP__":true,"debugInfo":{"code":"(write! #\"^start\")","line":1,"column":9},"source":"^start","flags":""}  
  (write! nil true false) => false  
inst-ms!

Returns milliseconds elapsed since the UNIX epoch.

inst-ms! => number
  (inst-ms!) => 1683389426447  
iso-date-time->inst-ms

Returns milliseconds elapsed since the UNIX epoch to date-time.

iso-date-time->inst-ms date-time => number
date-time: string
  (iso-date-time->inst-ms "2022-04-12T09:37:10.899Z") => 1649756230899  
  (iso-date-time->inst-ms "1980-01-01") => 315532800000  
inst-ms->iso-date-time

Returns IOS date time string from ms (milliseconds elapsed since the UNIX epoch).

inst-ms->iso-date-time ms => string
ms: number
  (inst-ms->iso-date-time 1649756230899) => "2022-04-12T09:37:10.899Z"  
  (inst-ms->iso-date-time 0) => "1970-01-01T00:00:00.000Z"  
debug!

If no params, prints context stack, otherwise prints value details.

debug! value => any
value: any
  (debug!) => null  
  (debug! #(> %1 2)) => <function λ>  
boolean

Coerces value to boolean.

boolean value => true | false
value: any
  (boolean 0) => false  
  (boolean 1) => true  
  (boolean nil) => false  
  (boolean "Albert") => true  
compare

Compares two values. Returns -1 if a < b, 1 if a > b and 0 if a and b have the same sort order.

compare a b => 1 | -1 | 0
a: any
b: any
  (compare 0 1) => -1  
  (compare "Albert" "Mojir") => -1  
  (compare 1 :1) => -1  
  (compare [1 2 3] [2 3]) => 1  
  (compare [1 2 3] [2 3 4]) => -1  
  (compare {:a 1 :b 2} {:a 1}) => 1  
  (compare {:a 1} [2 3]) => 1  
  (compare + -) => 0  
lits-version!

Returns the lits version.

lits-version! => string
  (lits-version!) => "1.0.0"  
uuid!

Returns UUID string.

uuid! => string
  (uuid!) => "de367c5d-025a-4106-963c-67450a0ca808"  
equal?

Returns true if a and b are structually equal.

equal? a b => boolean
a: any
b: any
  (equal? {:a 10 :b 20} {:b 20 :a 10}) => true  
  (equal? [1 true nil] [1 true nil]) => true  
  (equal? {:a 10 :b [1 2 {:b 20}]} {:b [1 2 {:b 20}] :a 10}) => true  
  (equal? {:a 10 :b [1 2 {:b 20}]} {:b [1 2 {:b 21}] :a 10}) => false  
  (= 0.3 (+ 0.1 0.2)) => false  
  (equal? 0.3 (+ 0.1 0.2)) => true  
dissoc

Return shallow copy of object with attribute attr deleted.

dissoc object attr => value
object: object
attr: string
  (dissoc (object :x 10 :y 20) :x) => {"y":20}  
  (dissoc { :x 10 } :y) => {"x":10}  
  (def o { :a 5 }) (dissoc o :a) o => {"a":5}  
object

Constructs a new object. Object members are created from key - value pairs. Requires an even number of arguments.

object [key value](zero or more) => object
[key value]: [string any]
  (object) => {}  
  (object :x 10 :y true :z "A string") => {"x":10,"y":true,"z":"A string"}  
  {} => {}  
  {:a 1 :b 2} => {"a":1,"b":2}  

Returns array of all keys in object.

keys object => array
object: object
  (keys (object)) => []  
  (keys (object :x 10 :y true :z "A string")) => ["x","y","z"]  

Returns array of all values in object.

vals object => array
object: object
  (vals (object)) => []  
  (vals (object :x 10 :y true :z "A string")) => [10,true,"A string"]  
entries

Returns nested array of all key - value pairs in object.

entries object => array of [key value] - paris
object: object
  (entries (object)) => []  
  (entries (object :x 10 :y true :z "A string")) => [["x",10],["y",true],["z","A string"]]  

Returns entry for key, or nil if key not present in object.

find object key => Entry
object: object
key: string
  (find (object :a 1 :b 2) :b) => ["b",2]  
  (find (object :a 1 :b 2) :c) => null  
merge

Returns a new object created by merging together all arguments.

merge object(one or many) => object
object: object
  (merge (object :x 10) (object :y 20)) => {"x":10,"y":20}  
  (merge (object :x 10) (object :x 15 :y 20)) => {"x":15,"y":20}  
merge-with

Returns a new object created by merging together all arguments. If two keys appears in more than one object fn is used to calculate the new value.

merge-with fn object(one or many) => object
fn: Function
object: object
  (merge-with + (object :x 10) (object :y 20)) => {"x":10,"y":20}  
  (merge-with + (object :x 10) (object :x 15 :y 20)) => {"x":25,"y":20}  
  (merge-with - (object :x 10) (object :x 20) (object :x 30) (object :x 40)) => {"x":-80}  
zipmap

Returns a new object created by mapping keys to values.

zipmap keys values => object
keys: Array
values: Array
  (zipmap [:a :b :c] [10 nil [1 2 3]]) => {"a":10,"b":null,"c":[1,2,3]}  
  (zipmap [:a :b :c] [1]) => {"a":1}  
  (zipmap [] [10 nil [1 2 3]]) => {}  
select-keys

Returns an object containing only those entries in object whose key is in keys.

select-keys object keys => object
object: Object
keys: Array
  (select-keys {:a 1 :b 2 :c 3} [:a :b]) => {"a":1,"b":2}  
  (select-keys {:a 1} [:a :b]) => {"a":1}  
boolean?

Returns true if value is a boolean, otherwise false.

boolean? value => boolean
value: any
  (boolean? true) => true  
  (boolean? false) => true  
  (boolean? [1 2 3]) => false  
  (boolean? 0) => false  
  (boolean? "A string") => false  

Returns true if value is nil, otherwise false.

nil? value => boolean
value: any
  (nil? nil) => true  
  (nil? false) => false  
  (nil? [1 2 3]) => false  
  (nil? 0) => false  
  (nil? "A string") => false  
number?

Returns true if value is a number, otherwise false.

number? value => boolean
value: any
  (number? 0) => true  
  (number? 2) => true  
  (number? -0.12) => true  
  (number? false) => false  
  (number? [1 2 3]) => false  
  (number? "A string") => false  
string?

Returns true if value is a string, otherwise false.

string? value => boolean
value: any
  (string? "") => true  
  (string? "A string") => true  
  (string? (if true "A string" false)) => true  
  (string? false) => false  
  (string? [1 2 3]) => false  
  (string? 100) => false  
function?

Returns true if value is a function, otherwise false.

function? value => boolean
value: any
  (function? +) => true  
  (function? /) => true  
  (function? (fn [x y] (+ x y))) => true  
  (function? false) => false  
  (function? "false") => false  
  (function? [1 2 3]) => false  
integer?

Returns true if value is an integer, otherwise false.

integer? value => boolean
value: any
  (integer? 0) => true  
  (integer? -12) => true  
  (integer? 42) => true  
  (integer? 10.1) => false  
  (integer? (fn [x y] (+ x y))) => false  
  (integer? false) => false  
  (integer? "false") => false  
  (integer? [1 2 3]) => false  
array?

Returns true if value is an array, otherwise false.

array? value => boolean
value: any
  (array? []) => true  
  (array? [1 2 3]) => true  
  (array? (object :a 10)) => false  
  (array? 42) => false  
  (array? 10.1) => false  
  (array? (fn [x y] (+ x y))) => false  
object?

Returns true if value is an object, otherwise false.

object? value => boolean
value: any
  (object? (object :a 10)) => true  
  (object? (object)) => true  
  (object? 42) => false  
  (object? 10.1) => false  
  (object? (fn [x y] (+ x y))) => false  
  (object? #"^start") => false  
  (object? "false") => false  
  (object? [1 2 3]) => false  
coll?

Returns true if value is a Coll i.e. an array, an object or a string, otherwise false.

coll? value => boolean
value: any
  (coll? []) => true  
  (coll? [1 2 3]) => true  
  (coll? (object :a 10)) => true  
  (coll? "Albert") => true  
  (coll? 42) => false  
  (coll? 10.1) => false  
  (coll? (fn [x y] (+ x y))) => false  
seq?

Returns true if value is a Seq i.e. an array or a string, otherwise false.

seq? value => boolean
value: any
  (seq? []) => true  
  (seq? [1 2 3]) => true  
  (seq? (object :a 10)) => false  
  (seq? "Albert") => true  
  (seq? 42) => false  
  (seq? 10.1) => false  
  (seq? (fn [x y] (+ x y))) => false  
regexp?

Returns true if value is a regexp, otherwise false.

regexp? value => boolean
value: any
  (regexp? (regexp "^start")) => true  
  (regexp? #"^start") => true  
  (regexp? -12) => false  
  (regexp? (object)) => false  
  (regexp? 10.1) => false  
  (regexp? (fn [x y] (+ x y))) => false  
  (regexp? false) => false  
  (regexp? "false") => false  
  (regexp? [1 2 3]) => false  
zero?

Returns true if number is 0, otherwise false.

zero? number => boolean
number: number
  (zero? 0) => true  
  (zero? -0.0) => true  
  (zero? 1) => false  
  (zero? 0.1) => false  

Returns true if number is greater than 0, otherwise false.

pos? number => boolean
number: number
  (pos? 0) => false  
  (pos? -0.0) => false  
  (pos? 1) => true  
  (pos? -0.1) => false  

Returns true if number is less than 0, otherwise false.

neg? number => boolean
number: number
  (neg? 0) => false  
  (neg? -0.0) => false  
  (neg? 1) => false  
  (neg? -0.1) => true  
even?

Returns true if number is even, otherwise false.

even? number => boolean
number: number
  (even? 0) => true  
  (even? -0.0) => true  
  (even? -1) => false  
  (even? 2.1) => false  

Returns true if number is odd, otherwise false.

odd? number => boolean
number: number
  (odd? 1.0) => true  
  (odd? 1.001) => false  
  (odd? -1) => true  
  (odd? 2.1) => false  
finite?

Returns true if number is finite, otherwise false.

finite? number => boolean
number: number
  (finite? 1.0) => true  
  (finite? (/ 1 0)) => false  
  (finite? (/ -1 0)) => false  
  (finite? (sqrt -1)) => false  
nan?

Returns true if number is NaN (not a number), otherwise false.

nan? number => boolean
number: number
  (nan? 1.0) => false  
  (nan? (/ 1 0)) => false  
  (nan? (/ -1 0)) => false  
  (nan? (sqrt -1)) => true  
negative-infinity?

Returns true if number equals negative infinity, otherwise false.

negative-infinity? number => boolean
number: number
  (negative-infinity? 1.0) => false  
  (negative-infinity? (/ 1 0)) => false  
  (negative-infinity? (/ -1 0)) => true  
  (negative-infinity? (sqrt -1)) => false  
positive-infinity?

Returns true if number equals positive infinity, otherwise false.

positive-infinity? number => boolean
number: number
  (positive-infinity? 1.0) => false  
  (positive-infinity? (/ 1 0)) => true  
  (positive-infinity? (/ -1 0)) => false  
  (positive-infinity? (sqrt -1)) => false  
false?

Returns true if value is true, otherwise false.

false? value => boolean
value: any
  (false? false) => true  
  (false? true) => false  
  (false? 1) => false  
  (false? 0) => false  
true?

Returns true if value is true, otherwise false.

true? value => boolean
value: any
  (true? false) => false  
  (true? true) => true  
  (true? 1) => false  
  (true? 0) => false  
empty?

Returns true if coll is empty, otherwise false.

empty? coll => boolean
coll: collection or string
  (empty? []) => true  
  (empty? [1 2 3]) => false  
  (empty? {}) => true  
  (empty? {:a 2}) => false  
  (empty? "") => true  
  (empty? "Albert") => false  
not-empty?

Returns false if coll is empty, otherwise true.

not-empty? coll => boolean
coll: collection or string
  (not-empty? []) => false  
  (not-empty? [1 2 3]) => true  
  (not-empty? {}) => false  
  (not-empty? {:a 2}) => true  
  (not-empty? "") => false  
  (not-empty? "Albert") => true  
regexp

Creates a RegExp from pattern and flags.

regexp pattern flags => RegExp
pattern: string
flags: string
  (regexp "^\s*(.*)$") => {"__REGEXP__":true,"debugInfo":{"code":"(regexp \"^\\s*(.*)$\")","line":1,"column":2},"source":"^\\s*(.*)$","flags":""}  
  #"^\s*(.*)$" => {"__REGEXP__":true,"debugInfo":{"code":"#\"^\\s*(.*)$\"","line":1,"column":1},"source":"^\\s*(.*)$","flags":""}  
  (regexp "albert" :i) => {"__REGEXP__":true,"debugInfo":{"code":"(regexp \"albert\" :i)","line":1,"column":2},"source":"albert","flags":"i"}  
  #"albert"ig => {"__REGEXP__":true,"debugInfo":{"code":"#\"albert\"ig","line":1,"column":1},"source":"albert","flags":"gi"}  
match

Matches string against pattern. If string matches, a match-array is returned, otherwise nil.

match pattern string => array
pattern: RegExp
string: string
  (match (regexp "^\s*(.*)$") "  A string") => ["  A string","A string"]  
  (match #"albert"i "My name is Albert") => ["Albert"]  
  (match #"albert"i "My name is Ben") => null  
replace

Returns a new string with some or all matches of pattern replaced by replacement.

replace string pattern replacement => array
string: string
pattern: RegExp
replacement: string
  (replace "Duck" (regexp :u) :i) => "Dick"  
  (replace "abcABC" (regexp :a "gi") "-") => "-bc-BC"  
  (replace "abcABC" #"a"gi "-") => "-bc-BC"  

Special Expression

Computes logical 'and' function. forms evaluation starts from left. Value from the first form that decides result is returned so forms at end of argument array may not evaluated.

and forms => boolean
forms: form[]
  (and 1 1) => 1  
  (and (> 3 2) "string") => "string"  
  (and (< 3 2) "string") => false  
  (and true true true true) => true  
  (and true true 0 true) => 0  

Special Expression

Computes logical 'or' function. forms evaluation starts from left. Value from the first form that decides result is returned so forms at end of argument array may not evaluated.

or forms => boolean
forms: form[]
  (or 1 1) => 1  
  (or (> 3 2) "string") => true  
  (or (< 3 2) "string") => "string"  
  (or true true true true) => true  
  (or 1 2 3 4) => 1  

Special Expression

Bind value to variable. If variable isn't defined, a new global variable is created.

def variable value => any
variable: name
value: any
  (def a (object)) => {}  
  (def a (object :x 10 :y true :z "A string")) => {"x":10,"y":true,"z":"A string"}  
defs

Special Expression

Creates a variable with name set to variable evaluated and value set to value. If a variable with name variable isn't found a new global variable is created.

defs variable value => any
variable: form
value: any
  (defs :a :b) => "b"  
  (defs (str :a :1) (object :x 10 :y true :z "A string")) a1 => {"x":10,"y":true,"z":"A string"}  
  (defs :a :b) (defs a :c) b => "c"  

Special Expression

Binds local variables. The variables lives only within the body. It returns evaluation of the last expression in the body.

let bindings body => any
bindings: bindings
body: lisp expressions
  (let [a (+ 1 2 3 4) b (* 1 2 3 4)] (write! a b)) => 24  
if-let

Special Expression

Binds one local variable. If it evaluates to a truthy value the then-form is executed with the variable accessable. If the bound variable evaluates to false, the then-form is evaluated (without variable accessable).

if-let bindings then else(optional) => any
bindings: bindings
then: any
else: any
  (if-let [a (> (count "Albert") 4)] (write! (str a "is big enough")) (write! "Sorry, not big enough.")) => "trueis big enough"  
  (if-let [a (> (count "Albert") 10)] (write! (str a "is big enough")) (write! "Sorry, not big enough.")) => "Sorry, not big enough."  
when-let

Special Expression

Binds one local variable. If it evaluates to a truthy value the then-form is executed with the variable accessable. If the bound variable evaluates to false, nil is returned.

when-let bindings then => any
bindings: bindings
then: any
  (when-let [a (> (count "Albert") 4)] (write! (str a "is big enough")) (write! "Sorry, not big enough.")) => "Sorry, not big enough."  
  (when-let [a (> (count "Albert") 10)] (write! (str a "is big enough")) (write! "Sorry, not big enough.")) => null  
when-first

Special Expression

Roughly the same as (when (seq xs) (let [x (first xs)] body)).

when-first bindings then => any
bindings: bindings
then: any
  (when-first [x [1 2 3]] (write! 10) (write! 20) x) => 1  
  (when-first [x "Albert"] x) => "A"  
  (when-first [x ""] x) => null  
  (when-first [x []] x) => null  

Special Expression

Creates a function. When called, evaluation of the last expression in the body is returned.

fn arguments body => function
arguments: arguments
body: lisp expressions
  (fn [a b] (sqrt (+ (* a a) (* b b)))) => <function λ>  
  ((fn [a b] (sqrt (+ (* a a) (* b b)))) 3 4) => 5  

Special Expression

Creates a named global function. When called, evaluation of the last expression in the body is returned.

defn name arguments body => function
name: name
arguments: arguments
body: lisp expressions
  (defn hyp [a b] (sqrt (+ (* a a) (* b b)))) hyp => <function hyp>  
  (defn hyp [a b] (sqrt (+ (* a a) (* b b)))) (hyp 3 4) => 5  
  (defn sumOfSquares [& s] (apply + (map (fn [x] (* x x)) s))) (sumOfSquares 1 2 3 4 5) => 55  
defns

Special Expression

Creates a named global function with its name set to name evaluated. When called, evaluation of the last expression in the body is returned.

defns name arguments body => function
name: form
arguments: arguments
body: lisp expressions
  (defns "hyp" [a b] (sqrt (+ (* a a) (* b b)))) hyp => <function hyp>  
  (defns (str :h :y :p) [a b] (sqrt (+ (* a a) (* b b)))) (hyp 3 4) => 5  
  (defns "sumOfSquares" [& s] (apply + (map (fn [x] (* x x)) s))) (sumOfSquares 1 2 3 4 5) => 55  
try

Special Expression

Executes tryExpression. If that throws, the catchBlock gets executed. See examples for details.

try tryExpression catchBlock => any
tryExpression: form
catchBlock: catchBlock
  (try (/ 2 4) (catch error (/ 2 1))) => 0.5  
  (try (/ 2 0) (catch error (/ 2 1))) => null  
  (try (/ 2 0) (catch error error)) => null  
throw

Special Expression

Throws UserDefinedError with message set to message evaluated. message must evaluate to a string.

throw message => nothing
message: form
  (try (throw "You shall not pass!") (catch e e)) => UserDefinedError: You shall not pass!
(try (throw "You shall not pass!") (catch e e))
            ^                                    
  (try (throw (subs "You shall not pass!" 0 3)) (catch e e)) => UserDefinedError: You
(try (throw (subs "You shall not pass!" 0 3)) (catch e e))
            ^                                               
  (try (throw "You shall not pass!") (catch error error)) => UserDefinedError: You shall not pass!
(try (throw "You shall not pass!") (catch error error))
            ^                                            

Special Expression

Either then or else branch is taken. Then branch is selected when test result is truthy. I test is falsy and no else branch exists, nil is returned.

if test then else(optional) => any
test: any
then: any
else: any
  (if true (write! "TRUE") (write! "FALSE")) => "TRUE"  
  (if false (write! "TRUE") (write! "FALSE")) => "FALSE"  
  (if true (write! "TRUE")) => "TRUE"  
  (if false (write! "TRUE")) => null  
if-not

Special Expression

Either then or else branch is taken. Then branch is selected when test result is falsy. I test is falsy and no else branch exists, nil is returned.

if-not test then else(optional) => any
test: any
then: any
else: any
  (if-not true (write! "TRUE") (write! "FALSE")) => "FALSE"  
  (if-not false (write! "TRUE") (write! "FALSE")) => "TRUE"  
  (if-not true (write! "TRUE")) => null  
  (if-not false (write! "TRUE")) => "TRUE"  

Special Expression

Used for branching. Variants are tested sequentially from the top. If no branch is tested truthy, nil is returned.

cond variants => any
variants: variants
  (cond false (write! "FALSE") nil (write! "nil") true (write! "TRUE")) => "TRUE"  
  (cond false (write! "FALSE") nil (write! "nil")) => null  

Special Expression

If test yields a thruthy value, the forms are evaluated in order from left to right and the value returned by the last form is returned. Otherwise, if test yields a falsy value, the forms are not evaluated, and nil is returned. If no form is provided, nil is returned.

when test form(zero or more) => any
test: form
form: form
  (when true (write! "Hi") (write! "There")) => "There"  
  (when false (write! "Hi") (write! "There")) => null  
  (when true) => null  
  (when false) => null  
when-not

Special Expression

If test yields a falsy value, the forms are evaluated in order from left to right and the value returned by the last form is returned. Otherwise, if test yields a truthy value, the forms are not evaluated, and nil is returned. If no form is provided, nil is returned.

when-not test form(zero or more) => any
test: form
form: form
  (when-not true (write! "Hi") (write! "There")) => null  
  (when-not false (write! "Hi") (write! "There")) => "There"  
  (when-not true) => null  
  (when-not false) => null  
comment

Special Expression

All forms within comment are read and must be valid lits but they are not eveluated. nil is returned.

comment forms => nil
forms: form[]
  (comment (write! "Hi") (write! "Albert")) => null  
  (comment) => null  

Special Expression

Calls forms in the order they have been written. Resulting value is the value of the last form.

do forms => any
forms: form[]
  (do (write! "Hi") (write! "Albert")) => "Albert"  
  (do) => null  
recur

Special Expression

Recursevly calls enclosing function or loop with its evaluated forms.

recur forms => nil
forms: form[]
  (defn foo [n] (write! n) (when (not (zero? n)) (recur (dec n)))) (foo 3) => null  
  ((fn [n] (write! n) (when (not (zero? n)) (recur (dec n)))) 3) => null  
  (loop [n 3] (write! n) (when (not (zero? n)) (recur (dec n)))) => null  

Special Expression

Executes body with initial bindings. The bindings will be replaced with the recur parameters for subsequent recursions.

loop bindings body => any
bindings: bindings
body: lisp expressions
  (loop [n 3] (write! n) (when (not (zero? n)) (recur (dec n)))) => null  
  (loop [n 3] (write! n) (if (not (zero? n)) (recur (dec n)) n)) => 0  
time!

Special Expression

Prints the time it took to evaluate form. Returns form evaluated.

time! form => any
form: any
  (defn fib [x] (if (<= x 2) 1 (+ (fib (dec x)) (fib (- x 2))))) (time! (fib 10)) => 55  
doseq

Special Expression

Same syntax as for, but returns nil. Use for side effects. Consumes less memory than for.

doseq bindings expression => nil
bindings: bindings
expression: form
  (doseq [x [1 2 4]] (write! x)) => null  

Special Expression

List comprehension. Takes an array of one or more bindings, each followed by zero or more modifiers, and returns an array of evaluations of expression. Collections are iterated in a nested fashion, rightmost fastest. Supported modifiers are: &let &while and &when.

for bindings expression => Array
bindings: bindings
expression: form
  (for [x "Al" y [1 2]] (repeat y x)) => [["A"],["A","A"],["l"],["l","l"]]  
  (for [x {:a 10 :b 20} y [1 2]] (repeat y x)) => [[["a",10]],[["a",10],["a",10]],[["b",20]],[["b",20],["b",20]]]  
  (for [x [1 2] y [1 10]] (* x y)) => [1,10,2,20]  
  (for [x [1 2] &let [z (* x x x)]] z) => [1,8]  
  (for [x [0 1 2 3 4 5] &let [y (* x 3)] &when (even? y)] y) => [0,6,12]  
  (for [x [0 1 2 3 4 5] &let [y (* x 3)] &while (even? y)] y) => [0]  
  (for [x [0 1 2 3 4 5] &let [y (* x 3)] &while (odd? y)] y) => []  
  (for [x [1 2 3] y [1 2 3] &while (<= x y) z [1 2 3]] [x y z]) => [[1,1,1],[1,1,2],[1,1,3],[1,2,1],[1,2,2],[1,2,3],[1,3,1],[1,3,2],[1,3,3]]  
  (for [x [1 2 3] y [1 2 3] z [1 2 3] &while (<= x y)] [x y z]) => [[1,1,1],[1,1,2],[1,1,3],[1,2,1],[1,2,2],[1,2,3],[1,3,1],[1,3,2],[1,3,3],[2,2,1],[2,2,2],[2,2,3],[2,3,1],[2,3,2],[2,3,3],[3,3,1],[3,3,2],[3,3,3]]  
declared?

Special Expression

Returns true if name is a declared variable or a builtin function.

declared? name => boolean
name: string
  (declared? foo) => false  
  (def foo :foo) (declared? foo) => true  
  (declared? +) => true  
  (def foo nil) (declared? foo) => true  
  (declared? if) => true  

Special Expression

Sort of like or with a couple of differences.

1. test does not need to be declared (defaults to nil)
2. Accept exactly one or two parameters.

?? test default(optional) => any
test: any
default: any
  (?? foo) => null  
  (def foo :foo) (?? foo) => "foo"  
  (?? +) => <function +>  
  (def foo nil) (?? foo) => null  
  (?? foo 1) => 1  
  (?? "") => ""  
  (?? 0) => 0  
  (?? 0 1) => 1  
  (?? 2 1) => 2  

Extracts characters from indexStart up to but not including indexEnd.

subs string indexStart indexEnd(optional) => string
string: string
indexStart: integer
indexEnd: integer
  (subs "A string" 2) => "string"  
  (subs "A string" 2 5) => "str"  
  (subs "A string" 2 100) => "string"  
  (subs "A string" 100) => ""  
string-repeat

Repeates string count times.

string-repeat string count => number
string: string
count: integer
  (string-repeat "*" 10) => "**********"  
  (string-repeat "***" 0) => ""  

Concatenats values into one string. If value equals nil empty string is returned.

str value(zero or more) => number
value: any
  (str "A string" ", and another string" " ...and more") => "A string, and another string ...and more"  
  (str "Just one string") => "Just one string"  
  (str) => ""  
  (str 0 false true nil #"^kalle" [1 2 3] {:a :a}) => "0falsetrue[object Object][1,2,3]{\"a\":\"a\"}"  
number

Parses string to a number.

number string => number
string: string
  (number "10") => 10  
  (number "010") => 10  
  (number "-1.01") => -1.01  
number-to-string

Converts number to a string. If base is not equal to 10 nu mber must be a non negative integer.

number-to-string number base => string
number: number
base: number: 2, 8, 10 or 16
  (number-to-string 10) => "10"  
  (number-to-string -1.01) => "-1.01"  
  (number-to-string -.01) => "-0.01"  
  (number-to-string 15 2) => "1111"  
  (number-to-string 15 8) => "17"  
  (number-to-string 15 16) => "f"  
lower-case

Returns string converted to lower case.

lower-case string => string
string: string
  (lower-case "Albert") => "albert"  
  (lower-case "") => ""  
upper-case

Returns string converted to upper case.

upper-case string => string
string: string
  (upper-case "Albert") => "ALBERT"  
  (upper-case "") => ""  
trim

Returns a new string with leading and trailing whitespaces removed.

trim string => string
string: string
  (trim "  Albert  ") => "Albert"  
  (trim "   ") => ""  
  (trim "") => ""  
trim-left

Returns a new string with leading whitespaces removed.

trim-left string => string
string: string
  (trim-left "  Albert  ") => "Albert  "  
  (trim-left "   ") => ""  
  (trim-left "") => ""  
trim-right

Returns a new string with trailing whitespaces removed.

trim-right string => string
string: string
  (trim-right "  Albert  ") => "  Albert"  
  (trim-right "   ") => ""  
  (trim-right "") => ""  
pad-left

Pads from the start of string with padString (multiple times, if needed) until the resulting string reaches the given length.

pad-left string length padString(optional) => string
string: string
length: integer
padString: string
  (pad-left "Albert" 20) => "              Albert"  
  (pad-left "Albert" 20 "-*-") => "-*--*--*--*--*Albert"  
  (pad-left "Albert" 5) => "Albert"  
  (pad-left "Albert" -1) => "Albert"  
pad-right

Pads from the start of string with padString (multiple times, if needed) until the resulting string reaches the given length.

pad-right string length padString(optional) => string
string: string
length: integer
padString: string
  (pad-right "Albert" 20) => "Albert              "  
  (pad-right "Albert" 20 "-*-") => "Albert-*--*--*--*--*"  
  (pad-right "Albert" 5) => "Albert"  
  (pad-right "Albert" -1) => "Albert"  
split

Divides string into an array of substrings. The division is done by searching for delimiter. If limit as provided, at most limit number of substrings are returned.

split string delimiter limit(optional) => string
string: string
delimiter: string
limit: non negative integer
  (split "Albert Mojir" " ") => ["Albert","Mojir"]  
  (split "abcdefghijklmnopqrstuvw" (regexp "[aoueiy]")) => ["","bcd","fgh","jklmn","pqrst","vw"]  
  (split "0123456789" "") => ["0","1","2","3","4","5","6","7","8","9"]  
  (map number (split "0123456789" "" 5)) => [0,1,2,3,4]  
template

Applies placeholders to a string. Support for basic pluralization - see examples. If pluralization is used, first placeholder must be a number.

template templateString placeholder(zero to nine) => string
templateString: string
placeholder: string
  (template "Hi, $1 and $2" "Carl" "Larry") => "Hi, Carl and Larry"  
  (template "Hi $1, $2, $3, $4, $5, $6, $7, $8 and $9" :A :B :C :D :E :F :G :H :I) => "Hi A, B, C, D, E, F, G, H and I"  
  (template "$1 book||||$1 books" 0) => "0 books"  
  (template "$1 book||||$1 books" 1) => "1 book"  
  (template "$1 book||||$1 books" 2) => "2 books"  
  (template "No book||||$1 book||||$1 books" 0) => "No book"  
  (template "No book||||$1 book||||$1 books" 1) => "1 book"  
  (template "No book||||$1 book||||$1 books" 10) => "10 books"  
  (template "No book||||One book||||Two books||||Three books||||$1 books" 0) => "No book"  
  (template "No book||||One book||||Two books||||Three books||||$1 books" 1) => "One book"  
  (template "No book||||One book||||Two books||||Three books||||$1 books" 2) => "Two books"  
  (template "No book||||One book||||Two books||||Three books||||$1 books" 3) => "Three books"  
  (template "No book||||One book||||Two books||||Three books||||$1 books" 4) => "4 books"  
to-char-code

Return code point for first character in input.

to-char-code input => number
input: string
  (to-char-code :A) => 65  
  (to-char-code "Albert") => 65  
from-char-code

Return character for code point code.

from-char-code code => string
code: number
  (from-char-code 65) => "A"  
  (from-char-code 0) => "\u0000"  
encode-base64

Returns a Base64 encoded string from value.

encode-base64 value => string
value: string
  (encode-base64 "Albert 🐻") => "QWxiZXJ0IPCfkLs="  
decode-base64

Returns a Base64 decoded string from base64string.

decode-base64 base64string => string
base64string: string
  (decode-base64 "QWxiZXJ0IPCfkLs=") => "Albert 🐻"  
encode-uri-component

Returns an escaped uri string.

encode-uri-component uri => string
uri: string
  (encode-uri-component "Hi everyone!? 👍") => "Hi%20everyone!%3F%20%F0%9F%91%8D"  
decode-uri-component

Returns an un-escaped uri string.

decode-uri-component uri => string
uri: string
  (decode-uri-component "Hi%20everyone!%3F%20%F0%9F%91%8D") => "Hi everyone!? 👍"  
bit-shift-left

Shifts number arithmetically left by count bit positions if count.

bit-shift-left number count => integer
number: integer
count: non negative integer
  (bit-shift-left 1 10) => 1024  
  (bit-shift-left -4 2) => -16  
bit-shift-right

Shifts number arithmetically right by count bit positions if count.

bit-shift-right number count => integer
number: integer
count: non negative integer
  (bit-shift-right 2048 10) => 2  
  (bit-shift-right 4 10) => 0  
bit-not

Returns bitwise not of number.

bit-not number => integer
number: integer
  (bit-not 0) => -1  
  (bit-not 255) => -256  
bit-and

Returns bitwise and of all arguments.

bit-and number(two or more) => integer
number: integer
  (bit-and 0b0011 0b0110) => 2  
  (bit-and 0b0011 0b0110 0b1001) => 0  
bit-and-not

Returns bitwise and with complement of all arguments. (bit-and-not x y) <==> (bit-and x (bit-not y)).

bit-and-not number(two or more) => integer
number: integer
  (bit-and-not 0b0011 0b0110) => 1  
  (bit-and-not 0b0011 0b0110 0b1001) => 0  
bit-or

Returns bitwise or of all arguments. Return 0 if no arguments.

bit-or number(two or more) => integer
number: integer
  (bit-or 0b0011 0b0110) => 7  
  (bit-or 0b1000 0b0100 0b0010) => 14  
bit-xor

Returns bitwise xor of all arguments.

bit-xor number(two or more) => integer
number: integer
  (bit-xor 0b0011 0b0110) => 5  
  (bit-xor 0b11110000 0b00111100 0b10101010) => 102  
bit-flip

Flips bit number index.

bit-flip number index => integer
number: integer
index: non negative integer
  (bit-flip 0b0011 1) => 1  
  (bit-flip 0b1100 1) => 14  
bit-clear

Clears bit number index.

bit-clear number index => integer
number: integer
index: non negative integer
  (bit-clear 0b0011 1) => 1  
  (bit-clear 0b1100 1) => 12  
bit-set

Sets bit number index.

bit-set number index => integer
number: integer
index: non negative integer
  (bit-set 0b0011 1) => 3  
  (bit-set 0b1100 1) => 14  
bit-test

Checks if bit number index is set.

bit-test number index => boolean
number: integer
index: non negative integer
  (bit-test 0b0011 1) => true  
  (bit-test 0b1100 1) => false  
assert

If value is falsy it throws AssertionError with message. If no message is provided, message is set to value.

assert value message(optional) => any
value: any
message: string
  (try (assert 0 "Expected a positive value") (catch e e)) => AssertionError: Expected a positive value
(try (assert 0 "Expected a positive value") (catch e e))
      ^                                                   
assert=

If first is not the same as second it throws AssertionError.

assert= first second message(optional) => nil
first: any
second: any
message: string
  (try (assert= 0 1 "Expected same values") (catch e e)) => AssertionError: Expected 0 to be 1. "Expected same values"
(try (assert= 0 1 "Expected same values") (catch e e))
      ^                                                 
  (try (assert= 0 1) (catch e e)) => AssertionError: Expected 0 to be 1.
(try (assert= 0 1) (catch e e))
      ^                          
  (try (assert= 1 1) (catch e e)) => null  
assert-not=

If first is the same as second it throws AssertionError.

assert-not= first second message(optional) => nil
first: any
second: any
message: string
  (try (assert-not= 0 0 "Expected different values") (catch e e)) => AssertionError: Expected 0 not to be 0. "Expected different values"
(try (assert-not= 0 0 "Expected different values") (catch e e))
      ^                                                          
  (try (assert-not= 0 0) (catch e e)) => AssertionError: Expected 0 not to be 0.
(try (assert-not= 0 0) (catch e e))
      ^                              
  (try (assert-not= 0 1) (catch e e)) => null  
assert-equal

If first is not deep equal to second it throws AssertionError.

assert-equal first second message(optional) => nil
first: any
second: any
message: string
  (try (assert-equal { :a 1 } { :a 2 } "Expected equal values") (catch e e)) => AssertionError: Expected
{
  "a": 1
}
to deep equal
{
  "a": 2
}. "Expected equal values"
(try (assert-equal { :a 1 } { :a 2 } "Expected equal values") (catch e e))
      ^                                                                     
  (try (assert-equal { :a 1 } { :a 2 }) (catch e e)) => AssertionError: Expected
{
  "a": 1
}
to deep equal
{
  "a": 2
}.
(try (assert-equal { :a 1 } { :a 2 }) (catch e e))
      ^                                             
  (try (assert-equal { :a 1 } { :a 1 }) (catch e e)) => null  
assert-not-equal

If first is not deep equal to second it throws AssertionError.

assert-not-equal first second message(optional) => nil
first: any
second: any
message: string
  (try (assert-not-equal { :a 2 } { :a 2 } "Expected different values") (catch e e)) => AssertionError: Expected {"a":2} not to deep equal {"a":2}. "Expected different values"
(try (assert-not-equal { :a 2 } { :a 2 } "Expected different values") (catch e e))
      ^                                                                             
  (try (assert-not-equal { :a 2 } { :a 2 }) (catch e e)) => AssertionError: Expected {"a":2} not to deep equal {"a":2}.
(try (assert-not-equal { :a 2 } { :a 2 }) (catch e e))
      ^                                                 
  (try (assert-not-equal { :a 1 } { :a 2 }) (catch e e)) => null  
assert>

If first is not greater than second it throws AssertionError.

assert> first second message(optional) => nil
first: any
second: any
message: string
  (try (assert> 0 1 "Expected greater value") (catch e e)) => AssertionError: Expected 0 to be grater than 1. "Expected greater value"
(try (assert> 0 1 "Expected greater value") (catch e e))
      ^                                                   
  (try (assert> 0 0) (catch e e)) => AssertionError: Expected 0 to be grater than 0.
(try (assert> 0 0) (catch e e))
      ^                          
  (try (assert> 1 0) (catch e e)) => null  
assert<

If first is not less than second it throws AssertionError.

assert< first second message(optional) => nil
first: any
second: any
message: string
  (try (assert< 1 0 "Expected smaller value value") (catch e e)) => AssertionError: Expected 1 to be less than 0. "Expected smaller value value"
(try (assert< 1 0 "Expected smaller value value") (catch e e))
      ^                                                         
  (try (assert< 1 1) (catch e e)) => AssertionError: Expected 1 to be less than 1.
(try (assert< 1 1) (catch e e))
      ^                          
  (try (assert< 0 1) (catch e e)) => null  
assert>=

If first is less than second it throws AssertionError.

assert>= first second message(optional) => nil
first: any
second: any
message: string
  (try (assert>= 0 1 "Expected greater value") (catch e e)) => AssertionError: Expected 0 to be grater than or equal to 1. "Expected greater value"
(try (assert>= 0 1 "Expected greater value") (catch e e))
      ^                                                    
  (try (assert>= 0 1) (catch e e)) => AssertionError: Expected 0 to be grater than or equal to 1.
(try (assert>= 0 1) (catch e e))
      ^                           
  (try (assert>= 1 1) (catch e e)) => null  
assert<=

If first is grater than second it throws AssertionError.

assert<= first second message(optional) => nil
first: any
second: any
message: string
  (try (assert<= 1 0 "Expected smaller value value") (catch e e)) => AssertionError: Expected 1 to be less than or equal to 0. "Expected smaller value value"
(try (assert<= 1 0 "Expected smaller value value") (catch e e))
      ^                                                          
  (try (assert<= 1 0) (catch e e)) => AssertionError: Expected 1 to be less than or equal to 0.
(try (assert<= 1 0) (catch e e))
      ^                           
  (try (assert<= 1 1) (catch e e)) => null  
assert-true

If first is not true it throws AssertionError.

assert-true first message(optional) => nil
first: any
message: string
  (try (assert-true false "Expected true") (catch e e)) => AssertionError: Expected false to be true. "Expected true"
(try (assert-true false "Expected true") (catch e e))
      ^                                                
  (try (assert-true false) (catch e e)) => AssertionError: Expected false to be true.
(try (assert-true false) (catch e e))
      ^                                
  (try (assert-true true) (catch e e)) => null  
assert-false

If first is not false it throws AssertionError.

assert-false first message(optional) => nil
first: any
message: string
  (try (assert-false true "Expected false") (catch e e)) => AssertionError: Expected true to be false. "Expected false"
(try (assert-false true "Expected false") (catch e e))
      ^                                                 
  (try (assert-false true) (catch e e)) => AssertionError: Expected true to be false.
(try (assert-false true) (catch e e))
      ^                                
  (try (assert-false false) (catch e e)) => null  
assert-truthy

If first is not truthy it throws AssertionError.

assert-truthy first message(optional) => nil
first: any
message: string
  (try (assert-truthy false "Expected truthy") (catch e e)) => AssertionError: Expected false to be truthy. "Expected truthy"
(try (assert-truthy false "Expected truthy") (catch e e))
      ^                                                    
  (try (assert-truthy false) (catch e e)) => AssertionError: Expected false to be truthy.
(try (assert-truthy false) (catch e e))
      ^                                  
  (try (assert-truthy 0) (catch e e)) => AssertionError: Expected 0 to be truthy.
(try (assert-truthy 0) (catch e e))
      ^                              
  (try (assert-truthy nil) (catch e e)) => AssertionError: Expected null to be truthy.
(try (assert-truthy nil) (catch e e))
      ^                                
  (try (assert-truthy "") (catch e e)) => AssertionError: Expected  to be truthy.
(try (assert-truthy "") (catch e e))
      ^                               
  (assert-truthy true) => null  
  (assert-truthy 1) => null  
  (assert-truthy :x) => null  
  (assert-truthy []) => null  
  (assert-truthy {}) => null  
assert-falsy

If first is not falsy it throws AssertionError.

assert-falsy first message(optional) => nil
first: any
message: string
  (try (assert-falsy true "Expected falsy") (catch e e)) => AssertionError: Expected true to be falsy. "Expected falsy"
(try (assert-falsy true "Expected falsy") (catch e e))
      ^                                                 
  (try (assert-falsy :x) (catch e e)) => AssertionError: Expected x to be falsy.
(try (assert-falsy :x) (catch e e))
      ^                              
  (try (assert-falsy []) (catch e e)) => AssertionError: Expected  to be falsy.
(try (assert-falsy []) (catch e e))
      ^                              
  (try (assert-falsy {}) (catch e e)) => AssertionError: Expected [object Object] to be falsy.
(try (assert-falsy {}) (catch e e))
      ^                              
  (try (assert-falsy 1) (catch e e)) => AssertionError: Expected 1 to be falsy.
(try (assert-falsy 1) (catch e e))
      ^                             
  (assert-falsy false) => null  
  (assert-falsy 0) => null  
  (assert-falsy nil) => null  
  (assert-falsy "") => null  
assert-nil

If first is not nil it throws AssertionError.

assert-nil first message(optional) => nil
first: any
message: string
  (assert-nil nil) => null  
  (try (assert-nil true "Expected nil") (catch e e)) => AssertionError: Expected true to be nil. "Expected nil"
(try (assert-nil true "Expected nil") (catch e e))
      ^                                             
  (try (assert-nil :x) (catch e e)) => AssertionError: Expected x to be nil.
(try (assert-nil :x) (catch e e))
      ^                            
  (try (assert-nil []) (catch e e)) => AssertionError: Expected  to be nil.
(try (assert-nil []) (catch e e))
      ^                            
  (try (assert-nil {}) (catch e e)) => AssertionError: Expected [object Object] to be nil.
(try (assert-nil {}) (catch e e))
      ^                            
  (try (assert-nil 1) (catch e e)) => AssertionError: Expected 1 to be nil.
(try (assert-nil 1) (catch e e))
      ^                           
  (try (assert-nil false) (catch e e)) => AssertionError: Expected false to be nil.
(try (assert-nil false) (catch e e))
      ^                               
  (try (assert-nil 0) (catch e e)) => AssertionError: Expected 0 to be nil.
(try (assert-nil 0) (catch e e))
      ^                           
  (try (assert-nil "") (catch e e)) => AssertionError: Expected  to be nil.
(try (assert-nil "") (catch e e))
      ^                            
assert-throws

If func does not throw, it throws AssertionError.

assert-throws func message(optional) => nil
func: Function
message: string
  (assert-throws #(throw "Error")) => null  
  (try (assert-throws #(identity "Error")) (catch e e)) => AssertionError: Expected function to throw.
(try (assert-throws #(identity "Error")) (catch e e))
      ^                                                
assert-throws-error

If func does not throw expectedMessage, it throws AssertionError.

assert-throws-error func expectedMessage message(optional) => nil
func: Function
expectedMessage: string
message: string
  (assert-throws-error #(throw "Error") "Error") => null  
  (try (assert-throws #(throw "Not Error")) (catch e e)) => null  
  (try (assert-throws #(identity "Error")) (catch e e)) => AssertionError: Expected function to throw.
(try (assert-throws #(identity "Error")) (catch e e))
      ^                                                
assert-not-throws

If func throws, it throws AssertionError.

assert-not-throws func message(optional) => nil
func: Function
message: string
  (assert-not-throws #(identity "Error")) => null  
  (try (assert-not-throws #(throw "Error")) (catch e e)) => AssertionError: Expected function not to throw.
(try (assert-not-throws #(throw "Error")) (catch e e))
      ^                                                 
Playground
Run [F2] Analyze [F3] Tokenize [F4] Tokenize (debug) [F5] Parse [F6] Parse (debug) [F7] Reset
Clear
Clear
Clear