API

%#

(% dividend divisor)

Return the remainder of dividend / divisor.

*#

(* & xs)

Returns the product of all elements in xs. All elements in xs must be numbers. If xs is empty, return 1.

**#

(** a x)

Return a to the power of x.

+#

(+ & xs)

Returns the sum of all elements in xs. All elements xs must be numbers. If xs is empty, return 0.

-#

(- & xs)

Returns the difference of all elements in xs. If xs is empty, return 0. If xs has one element, return the negative value of that element.

->#

(-> x & forms)

Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, insert the first form as the second item in the second form, etc.

->>#

(->> x & forms)

Threads the expr through the forms. Inserts x as the last item in the first form, making a list of it if it is not a list already. If there are more forms, insert the first form as the last item in the second form, etc.

/#

(/ & xs)

Returns the nominator divided by all the denominators. If xs is empty, returns 1. If xs has one value, returns the reciprocal of x.

<#

(< a & more)

Checks if each argument is strictly less than the following argument. Returns a boolean.

<=#

(<= a & more)

Checks if each argument is less than or equal to the following argument. Returns a boolean.

<=>#

(<=> a b)

Alias for the spaceship PHP operator in ascending order. Returns an int.

=#

(= a & more)

Checks if all values are equal. Same as a == b in PHP.

>#

(> a & more)

Checks if each argument is strictly greater than the following argument. Returns a boolean.

>=#

(>= a & more)

Checks if each argument is greater than or equal to the following argument. Returns a boolean.

>=<#

(>=< a b)

Alias for the spaceship PHP operator in descending order. Returns an int.

*build-mode*#

Set to true when a file is being built/transpiled, false otherwise.

*compile-mode*#

Deprecated! Use build-mode instead. Set to true when a file is compiled, false otherwise.

*ns*#

NAN#

Constant for Not a Number (NAN) values.

nan?#

(nan? x)

Checks if x is not a number.

all?#

(all? pred xs)

Returns true if (pred x) is logical true for every x in xs, else false.

and#

(and & args)

Evaluates each expression one at a time, from left to right. If a form returns logical false, and returns that value and doesn't evaluate any of the other expressions, otherwise, it returns the value of the last expression. Calling the and function without arguments returns true.

argv#

Array of arguments passed to script.

as->#

(as-> expr name & forms)

Binds name to expr, evaluates the first form in the lexical context of that binding, then binds name to that result, repeating for each successive form, returning the result of the last form.

associative?#

(associative? x)

Returns true if x is an associative data structure, false otherwise.

binding#

(binding bindings & body)

Temporary redefines definitions while executing the body. The value will be reset after the body was executed.

bit-and#

(bit-and x y & args)

Bitwise and.

bit-clear#

(bit-clear x n)

Clear bit an index n.

bit-flip#

(bit-flip x n)

Flip bit at index n.

bit-not#

(bit-not x)

Bitwise complement.

bit-or#

(bit-or x y & args)

Bitwise or.

bit-set#

(bit-set x n)

Set bit an index n.

bit-shift-left#

(bit-shift-left x n)

Bitwise shift left.

bit-shift-right#

(bit-shift-right x n)

Bitwise shift right.

bit-test#

(bit-test x n)

Test bit at index n.

bit-xor#

(bit-xor x y & args)

Bitwise xor.

boolean?#

(boolean? x)

Returns true if x is a boolean, false otherwise.

case#

(case e & pairs)

Takes an expression e and a set of test-content/expression pairs. First evaluates e and then finds the first pair where the test-constant matches the result of e. The associated expression is then evaluated and returned. If no matches can be found a final last expression can be provided that is then evaluated and returned. Otherwise, nil is returned.

coerce-in#

(coerce-in v min max)

Returns v if it is in the range, or min if v is less than min, or max if v is greater than max.

comment#

(comment &)

Ignores the body of the comment.

comp#

(comp & fs)

Takes a list of functions and returns a function that is the composition of those functions.

compare#

(compare x y)

An integer less than, equal to, or greater than zero when x is less than, equal to, or greater than y, respectively.

compile#

(compile form)

Returns the compiled PHP code string for the given form.

complement#

(complement f)

Returns a function that takes the same arguments as f and returns the opposite truth value.

concat#

(concat arr & xs)

Concatenates multiple sequential data structures.

cond#

(cond & pairs)

Takes a set of test/expression pairs. Evaluates each test one at a time. If a test returns logically true, the expression is evaluated and returned. If no test matches a final last expression can be provided that is then evaluated and returned. Otherwise, nil is returned.

cons#

(cons x xs)

Prepends x to the beginning of xs.

contains-value?#

(contains-value? coll val)

Returns true if the value is present in the given collection, otherwise returns false.

contains?#

(contains? coll key)

Returns true if key is present in the given collection, otherwise returns false.

count#

(count xs)

Counts the number of elements in a sequence. Can be used on everything that implements the PHP Countable interface.

dec#

(dec x)

Decrements x by one.

declare#

(declare name)

Declare a global symbol before it is defined.

deep-merge#

(deep-merge & args)

Recursively merges data structures.

def-#

(def- name value)

Define a private value that will not be exported.

definterface#

(definterface name & fns)

Defines an interface.

defmacro#

(defmacro name & fdecl)

Define a macro.

defmacro-#

(defmacro- name & fdecl)

Define a private macro that will not be exported.

defn#

(defn name & fdecl)

Define a new global function.

defn-#

(defn- name & fdecl)

Define a private function that will not be exported.

defstruct#

(defstruct name keys & implementations)

Define a new struct.

deref#

(deref variable)

Return the value inside the variable.

difference#

(difference set & sets)

Difference between multiple sets into a new one.

difference-pair#

(difference-pair s1 s2)

distinct#

(distinct xs)

Returns a vector with duplicated values removed in xs.

dofor#

(dofor head & body)

Repeatedly executes body for side effects with bindings and modifiers as provided by for. Returns nil.

drop#

(drop n xs)

Drops the first n elements of xs.

drop-while#

(drop-while pred xs)

Drops all elements at the front xs where (pred x) is true.

empty?#

(empty? x)

Returns true if x would be 0, "" or empty collection, false otherwise.

eval#

(eval form)

Evaluates a form and return the evaluated results.

even?#

(even? x)

Checks if x is even.

extreme#

(extreme order args)

Returns the most extreme value in args based on the binary order function.

false?#

(false? x)

Checks if x is false. Same as x === false in PHP.

ffirst#

(ffirst xs)

Same as (first (first xs)).

filter#

(filter pred xs)

Returns all elements of xs where (pred x) is true.

find#

(find pred xs)

Returns the first item in xs where (pred item) evaluates to true.

find-index#

(find-index pred xs)

Returns the first item in xs where (pred index item) evaluates to true.

first#

(first xs)

Returns the first element of an indexed sequence or nil.

flatten#

(flatten xs)

Takes a nested sequential data structure (tree), and returns their contents as a single, flat vector.

float?#

(float? x)

Returns true if x is float point number, false otherwise.

for#

(for head & body)

List comprehension. The head of the loop is a vector that contains a sequence of bindings modifiers and options. A binding is a sequence of three values binding :verb expr. Where binding is a binding as in let and :verb is one of the following keywords:

  • :range loop over a range by using the range function.
  • :in loops over all values of a collection.
  • :keys loops over all keys/indexes of a collection.
  • :pairs loops over all key-value pairs of a collection.

After each loop binding, additional modifiers can be applied. Modifiers have the form :modifier argument. The following modifiers are supported:

  • :while breaks the loop if the expression is falsy.
  • :let defines additional bindings.
  • :when only evaluates the loop body if the condition is true.

Finally, additional options can be set:

  • :reduce [accumulator initial-value] Instead of returning a list, it reduces the values into accumulator. Initially accumulator is bound to initial-value.

format#

(format fmt & xs)

Returns a formatted string. See PHP's sprintf for more information.

frequencies#

(frequencies xs)

Returns a map from distinct items in xs to the number of times they appear.

full-name#

(full-name x)

Return the namespace and name string of a string, keyword or symbol.

function?#

(function? x)

Returns true if x is a function, false otherwise.

gensym#

(gensym )

Generates a new unique symbol.

get#

(get ds k & [opt])

Get the value mapped to key from the datastructure ds. Returns opt or nil if the value cannot be found.

get-in#

(get-in ds ks & [opt])

Access a value in a nested data structure. Looks into the data structure via a sequence of keys.

group-by#

(group-by f xs)

Returns a map of the elements of xs keyed by the result of f on each element.

hash-map#

(hash-map & xs)

Creates a new hash map. If no argument is provided, an empty hash map is created. The number of parameters must be even.

hash-map?#

(hash-map? x)

Returns true if x is a hash map, false otherwise.

html/doctype#

(doctype type)

html/escape-html#

(escape-html s)

Escapes the string that may contain HTML.

html/html#

(html & content)

html/raw-string#

(raw-string s)

Creates a new raw-string struct.

html/raw-string?#

(raw-string? x)

Checks if x is an instance of the raw-string struct.

http/create-response-from-map#

http/create-response-from-string#

http/emit-response#

(emit-response response)

Emits the response.

http/files-from-globals#

(files-from-globals & [files])

Extracts the files from $_FILES and normalizes them to a map of "uploaded-file".

http/headers-from-server#

(headers-from-server & [server])

Extracts all headers from the $_SERVER variable.

http/request#

(request method uri headers parsed-body query-params cookie-params server-params uploaded-files version attributes)

Creates a new request struct.

http/request?#

(request? x)

Checks if x is an instance of the request struct.

http/request-from-globals#

(request-from-globals )

Extracts a request from $_SERVER, $_GET, $_POST, $_COOKIE and $_FILES.

http/request-from-globals-args#

(request-from-globals-args server get-parameter post-parameter cookies files)

Extracts a request from args.

http/request-from-map#

(request-from-map {:method method :version version :uri uri :headers headers :parsed-body parsed-body :query-params query-params :cookie-params cookie-params :server-params server-params :uploded-files uploaded-files :attributes attributes})

http/response#

(response status headers body version reason)

Creates a new response struct.

http/response?#

(response? x)

Checks if x is an instance of the response struct.

http/response-from-map#

(response-from-map {:status status :headers headers :body body :version version :reason reason})

Creates a response struct from a map. The map can have the following keys:

  • :status The HTTP Status (default 200)
  • :headers A map of HTTP Headers (default: empty map)
  • :body The body of the response (default: empty string)
  • :version The HTTP Version (default: 1.1)
  • :reason The HTTP status reason. If not provided a common status reason is taken

http/response-from-string#

(response-from-string s)

Create a response from a string.

http/uploaded-file#

(uploaded-file tmp-file size error-status client-filename client-media-type)

Creates a new uploaded-file struct.

http/uploaded-file?#

(uploaded-file? x)

Checks if x is an instance of the uploaded-file struct.

http/uri#

(uri scheme userinfo host port path query fragment)

Creates a new uri struct.

http/uri?#

(uri? x)

Checks if x is an instance of the uri struct.

http/uri-from-globals#

(uri-from-globals & [server])

Extracts the URI from the $_SERVER variable.

http/uri-from-string#

(uri-from-string url)

Create a uri struct from a string

id#

(id a & more)

Checks if all values are identical. Same as a === b in PHP.

identity#

(identity x)

Returns its argument.

if-not#

(if-not test then & [else])

Shorthand for (if (not condition) else then).

inc#

(inc x)

Increments x by one.

indexed?#

(indexed? x)

Returns true if x is indexed sequence, false otherwise.

int?#

(int? x)

Returns true if x is an integer number, false otherwise.

interleave#

(interleave & xs)

Returns a vector with the first items of each col, then the second items, etc.

interpose#

(interpose sep xs)

Returns a vector of elements separated by sep.

intersection#

(intersection set & sets)

Intersect multiple sets into a new one.

invert#

(invert map)

Returns a new map where the keys and values are swapped. If map has duplicated values, some keys will be ignored.

json/decode#

(decode json & [{:flags flags :depth depth}])

Decodes a JSON string.

json/decode-value#

(decode-value x)

Convert a json data structure to a 'phel compatible' value.

json/encode#

(encode value & [{:flags flags :depth depth}])

Returns the JSON representation of a value.

json/encode-value#

(encode-value x)

Convert a Phel data type to a 'json compatible' value.

json/valid-key?#

(valid-key? v)

Checks if v is a valid JSON key or can be converted to a JSON key.

juxt#

(juxt & fs)

Takes a list of functions and returns a new function that is the juxtaposition of those functions. ((juxt a b c) x) => [(a x) (b x) (c x)].

keep#

(keep pred xs)

Returns a list of non-nil results of (pred x).

keep-indexed#

(keep-indexed pred xs)

Returns a list of non-nil results of (pred i x).

keys#

(keys xs)

Gets the keys of an associative data structure.

keyword#

(keyword x)

Creates a new Keyword from a given string.

keyword?#

(keyword? x)

Returns true if x is a keyword, false otherwise.

kvs#

(kvs xs)

Returns a vector of key-value pairs like [k1 v1 k2 v2 k3 v3 ...].

list#

(list & xs)

Creates a new list. If no argument is provided, an empty list is created.

list?#

(list? x)

Returns true if x is a list, false otherwise.

map#

(map f & xs)

Returns an array consisting of the result of applying f to all of the first items in each xs, followed by applying f to all the second items in each xs until anyone of the xs is exhausted.

map-indexed#

(map-indexed f xs)

Applies f to each element in xs. f is a two-argument function. The first argument is an index of the element in the sequence and the second element is the element itself.

mapcat#

(mapcat f & xs)

Applies f on all xs and concatenate the result.

max#

(max & numbers)

Returns the numeric maximum of all numbers.

mean#

(mean xs)

Returns the mean of xs.

merge#

(merge & maps)

Merges multiple maps into one new map. If a key appears in more than one collection, then later values replace any previous ones.

merge-with#

(merge-with f & hash-maps)

Merges multiple maps into one new map. If a key appears in more than one collection, the result of (f current-val next-val) is used.

meta#

(meta obj)

Gets the metadata of the given object.

min#

(min & numbers)

Returns the numeric minimum of all numbers.

name#

(name x)

Returns the name string of a string, keyword or symbol.

namespace#

(namespace x)

Return the namespace string of a symbol or keyword. Nil if not present.

neg?#

(neg? x)

Checks if x is smaller than zero.

next#

(next xs)

Returns the sequence of elements after the first element. If there are no elements, returns nil.

nfirst#

(nfirst xs)

Same as (next (first xs)).

nil?#

(nil? x)

Returns true if x is nil, false otherwise.

nnext#

(nnext xs)

Same as (next (next xs)).

not#

(not x)

The not function returns true if the given value is logical false and false otherwise.

not=#

(not= a & more)

Checks if all values are unequal. Same as a != b in PHP.

number?#

(number? x)

Returns true if x is a number, false otherwise.

odd?#

(odd? x)

Checks if x is odd.

one?#

(one? x)

Checks if x is one.

or#

(or & args)

Evaluates each expression one at a time, from left to right. If a form returns a logical true value, or returns that value and doesn't evaluate any of the other expressions, otherwise, it returns the value of the last expression. Calling or without arguments, returns nil.

pairs#

(pairs xs)

Gets the pairs of an associative data structure.

partial#

(partial f & args)

Takes a function f and fewer than normal arguments of f and returns a function that a variable number of additional arguments. When call f will be called with args and the additional arguments.

partition#

(partition n xs)

Partition an indexed data structure into vectors of maximum size n. Returns a new vector.

peek#

(peek xs)

Returns the last element of a sequence.

persistent#

(persistent coll)

Converts a transient collection to a persistent collection.

php-array-to-map#

(php-array-to-map arr)

Converts a PHP Array to a map.

php-array?#

(php-array? x)

Returns true if x is a PHP Array, false otherwise.

php-associative-array#

(php-associative-array & xs)

Creates a PHP associative array. An even number of parameters must be provided.

php-indexed-array#

(php-indexed-array & xs)

Creates a PHP indexed array from the given values.

php-object?#

(php-object? x)

Returns true if x is a PHP object, false otherwise.

php-resource?#

(php-resource? x)

Returns true if x is a PHP resource, false otherwise.

pop#

(pop xs)

Removes the last element of the array xs. If the array is empty returns nil.

pos?#

(pos? x)

Checks if x is greater than zero.

print#

(print & xs)

Prints the given values to the default output stream. Returns nil.

(print-str & xs)

Same as print. But instead of writing it to an output stream, the resulting string is returned.

printf#

(printf fmt & xs)

Output a formatted string. See PHP's printf for more information.

println#

(println & xs)

Same as print followed by a newline.

push#

(push xs x)

Inserts x at the end of the sequence xs.

put#

(put ds key value)

Puts value mapped to key on the datastructure ds. Returns ds.

put-in#

(put-in ds [k & ks] v)

Puts a value into a nested data structure.

rand#

(rand )

Returns a random number between 0 and 1.

rand-int#

(rand-int n)

Returns a random number between 0 and n.

rand-nth#

(rand-nth xs)

Returns a random item from xs.

range#

(range a & rest)

Create an array of values [start, end). If the function has one argument then the range [0, end) is returned. With two arguments, returns [start, end). The third argument is an optional step width (default 1).

re-seq#

(re-seq re s)

Returns a sequence of successive matches of pattern in string.

read-string#

(read-string s)

Reads the first phel expression from the string s.

reduce#

(reduce f init xs)

Transforms a collection xs with a function f to produce a value by applying f to each element in order. f is a function with two arguments. The first argument is the initial value and the second argument is the element of xs. f returns a value that will be used as the initial value of the next call to f. The final value of f is returned.

reduce2#

(reduce2 f [x & xs])

The 2-argument version of reduce that does not take an initialization value. Instead, the first argument of the list is used as initialization value.

remove#

(remove xs offset & [n])

Removes up to n element from array xs starting at index offset.

repeat#

(repeat n x)

Returns a vector of length n where every element is x.

repl/build-facade#

repl/compile-str#

(compile-str s)

repl/doc#

(doc sym)

Prints the documentation for the given symbol.

repl/print-colorful#

(print-colorful & xs)

Colored print.

repl/println-colorful#

(println-colorful & xs)

Colored println.

repl/require#

(require sym & args)

Requires a Phel module into the environment.

repl/resolve#

(resolve sym)

Resolves the given symbol in the current environment and returns a resolved Symbol with the absolute namespace or nil if it cannot be resolved.

repl/use#

(use sym & args)

Adds a use statement to the environment.

rest#

(rest xs)

Returns the sequence of elements after the first element. If there are no elements, returns an empty sequence.

reverse#

(reverse xs)

Reverses the order of the elements in the given sequence.

second#

(second xs)

Returns the second element of an indexed sequence or nil.

set#

(set & xs)

Creates a new Set. If no argument is provided, an empty Set is created.

set!#

(set! variable value)

Sets a new value to the given variable.

set?#

(set? x)

Returns true if x is a set, false otherwise.

set-meta!#

(set-meta! obj)

Sets the metadata to a given object.

shuffle#

(shuffle xs)

Returns a random permutation of xs.

slice#

(slice xs & [offset & [length]])

Extract a slice of xs.

some?#

(some? pred xs)

Returns true if (pred x) is logical true for at least one x in xs, else false.

sort#

(sort xs & [comp])

Returns a sorted vector. If no comparator is supplied compare is used.

sort-by#

(sort-by keyfn xs & [comp])

Returns a sorted vector where the sort order is determined by comparing (keyfn item). If no comparator is supplied compare is used.

split-at#

(split-at n xs)

Returns a vector of [(take n coll) (drop n coll)].

split-with#

(split-with f xs)

Returns a vector of [(take-while pred coll) (drop-while pred coll)].

str#

(str & args)

Creates a string by concatenating values together. If no arguments are provided an empty string is returned. Nil and false are represented as an empty string. True is represented as 1. Otherwise, it tries to call __toString. This is PHP equivalent to $args[0] . $args[1] . $args[2] ....

str-contains?#

(str-contains? str s)

Returns true if str contains s.

string?#

(string? x)

Returns true if x is a string, false otherwise.

struct?#

(struct? x)

Returns true if x is a struct, false otherwise.

sum#

(sum xs)

Returns the sum of all elements is xs.

swap!#

(swap! variable f & args)

Swaps the value of the variable to (apply f current-value args). Returns the values that are swapped in.

symbol?#

(symbol? x)

Returns true if x is a symbol, false otherwise.

symmetric-difference#

(symmetric-difference set & sets)

Symmetric difference between multiple sets into a new one.

take#

(take n xs)

Takes the first n elements of xs.

take-last#

(take-last n xs)

Takes the last n elements of xs.

take-nth#

(take-nth n xs)

Returns every nth item in xs.

take-while#

(take-while pred xs)

Takes all elements at the front of xs where (pred x) is true.

test/deftest#

(deftest test-name & body)

Defines a test function with no arguments.

test/is#

(is form & [message])

Generic assertion macro.

test/print-summary#

(print-summary )

Prints the summary of the test suite.

test/report#

(report data)

test/run-tests#

(run-tests options & namespaces)

Runs all test functions in the given namespaces.

test/successful?#

(successful? )

Checks if all tests have passed.

to-php-array#

(to-php-array xs)

Create a PHP Array from a sequential data structure.

transient#

(transient coll)

Converts a persistent collection to a transient collection.

tree-seq#

(tree-seq branch? children root)

Returns a vector of the nodes in the tree, via a depth-first walk. branch? is a function with one argument that returns true if the given node has children. children must be a function with one argument that returns the children of the node. root the root node of the tree.

true?#

(true? x)

Checks if x is true. Same as x === true in PHP.

truthy?#

(truthy? x)

Checks if x is truthy. Same as x == true in PHP.

type#

(type x)

Returns the type of x. The following types can be returned:

  • :vector
  • :list
  • :struct
  • :hash-map
  • :set
  • :keyword
  • :symbol
  • :var
  • :int
  • :float
  • :string
  • :nil
  • :boolean
  • :function
  • :php/array
  • :php/resource
  • :php/object
  • :unknown

union#

(union & sets)

Union multiple sets into a new one.

unset#

(unset ds key)

Returns ds without key.

update#

(update ds k f & args)

Updates a value in a datastructure by applying f to the current element and replacing it with the result of f.

update-in#

(update-in ds [k & ks] f & args)

Updates a value into a nested data structure.

values#

(values xs)

Gets the values of an associative data structure.

var#

(var value)

Creates a new variable with the given value.

var?#

(var? x)

Checks if the given value is a variable.

vector#

(vector & xs)

Creates a new vector. If no argument is provided, an empty vector is created.

vector?#

(vector? x)

Returns true if x is a vector, false otherwise.

when#

(when test & body)

Evaluates test and if that is logical true, evaluates body.

when-not#

(when-not test & body)

Evaluates test and if that is logical false, evaluates body.

with-output-buffer#

(with-output-buffer & body)

Everything that is printed inside the body will be stored in a buffer. The result of the buffer is returned.

zero?#

(zero? x)

Checks if x is zero.

zipcoll#

(zipcoll a b)

Creates a map from two sequential data structures. Return a new map.