Skip to content

6) cm (Built in Functions) Reference

Benjamin Pang edited this page Nov 15, 2016 · 13 revisions

Built-in functions are always prefixed and will only contain 1 or 2 arguments.

##I/O

Name Arguments Info
rl n/a string from user input
rf file path as string file contents as string
os expression outputs (no trailing newline) as source, returns arg
ol expression outputs (no trailing newline) as string, returns arg
wf file path as string, edits as string overwrites file with edit, returns edit

##Math/Number All of these functions are done with the help of All trig-related functions use radians.

Name Arguments Info
E 0 < integer <= 1000 sets decimal precision of numbers
abs number absolute value of number
asin, acos, atan, asinh, acosh, atanh number arctrig functions
atant number, number uses 2nd arg to determine sign of the atan function
flr, trunc, ceil, round number rounding functions
sin, cos, tan, sinh, cosh, tanh number trig functions
add, sub, mul, div, mod, pow number, number arithmetic operations
exp number e^number
lt, ln number base 10 and natural log
log number, number 2nd number is base
sign number -1, 0, or 1 depending on the number's sign
neg number negates number
rnd 0 < integer <= 1000 generates random float with given integer precision
hypot number, number (1st arg)^2 + (2nd arg)^2
hx, bn, ot number decimal to hex/binary/octal

##Logic

Name Arguments Info
cmp number, number -1, 0, or 1 if x is <, =, or > 1
lt, gt, lteq, gteq number, number comparison functions
eq expression, expression checks if 2 expressions are loosely equal; for strict equal, check for equal types
if expression, list w/ 2 functions if the expression is truthy, apply T to the 1st function in the list; otherwise, apply F to the 2nd function in the list
not expression logical NOT
and, or, xor expression, expression logical AND, OR, and XOR

##Conversion See Conversions for more info.

Name Arguments Info
eval string evaluate as expression
sh string execute shell command
js string execute Node.js code
fc number / list from charcode
tc string to charcode
bool expression to boolean
num string to number
str expression to string
src expression to source as string
type expression expression type
var variable, expression store expression under variable name
obj list w/ iterables of length>2 convert list to object w/ each iterable as a key-value pair
obl list convert list to object with indices as keys

##Iterables This includes lists, strings, numbers, and objects. Strings (and sometimes numbers) will often be treated as single-char lists.

Name Arguments Info
len iterable length
con iterable, expression concatenation; if the second argument is a list, it will concatenate each item in the list rather than the list itself
cat iterable, expression raw concatenation; concatenates with no special type treatment
rev iterable reverse
get number, iterable modular indexing
set list w/ index and expression, iterable change item at index to expression
ins list w/ index and expression, iterable add expression to list at index
tk number, iterable get the first n items in the iterable
tk number, iterable remove the first n items in the iterable
map function, iterable apply each item in list to function
fold list w/ function and expression, iterable expression is accumulator, folds w/ function and iterable
foldr list w/ function and expression, iterable same as fold but from the right
tkwh function, iterable takes elements from iterable until function returns truthy
drwl function, iterable drops elements from iterable until function returns truthy
fltr function, iterable remove elements that return falsy when applied to function
find function, iterable returns first element that returns truthy when applied to function
every function, iterable returns whether every element return truthy when applied to function
some function, iterable returns whether some elements return truthy when applied to function
sort function, iterable sort iterable based on the results of applying each item to function
sum iterable add all items in iterable
prod iterable multiply all items in iterable
chunk number, iterable chunk the iterable into parts with lengths of number
shuf iterable randomizes iterable's order
unq iterable removes duplicates
inx iterable, iterable set intersection
uni iterable, iterable set union
dff iterable, iterable set difference
cns number, iterable get consecutive overlapping sequences of length number
ind iterable wrap each item in the iterable with a list containing the index of the item and the item itself
cyc iterable generate an infinite list that repeats each item in the iterable

##List

Name Arguments Info
max, min list of numbers maximum and minimum numbers
rng number, number exclusive range; can be an infinite range
join string, list join list using string
gen function generates an infinite list from applying each index to the function
genc function,expression generates an infinite list from repeatedly applying the previous list item to the function
tsp list w/ 2 iterables transpose; swaps rows with columns
zip function, list w/ 2 lists map sS over the 2nd argument transposed
flat list flatten list by 1 level

##Object Some of these function can be used on lists.

Name Arguments Info
key object list of keys
val object list of values
pk list of keys,object pick key-value pairs whose key appear in the list
om list of keys,object omit key-value pairs whose key appear in the list

##String Some of these functions may apply to numbers, too.

Name Arguments Info
split regex, string split 1st arg using 2nd arg
mstr regex, string returns an object with all regex matches on the string, excluding capture group matches
xstr regex, string returns an object with the first regex match on the string along with other data
sstr regex, string returns the index of the first match
rstr list w/ regex and substitution function, string replace any matches in the string using the substitution function (which should take in a xstr-style list and return a substitution string/data) or string
lc string lowercase
uc string uppercase

##Function

Name Arguments Info
S expression, expression apply 2nd arg to 1st arg
ss list w/ functions, expression creates a composition of functions to apply to expression
sS function, list applies list items to function
K expression, expression return 1st arg
I expression return expression
tt function/partial application returns a function that applies arguments in reverse order; only works on builtins

##Program Flow

Name Arguments Info
sleep number halt the program for number of microseconds
exit expression stops the program completely
while list w/ 2 functions, expression repeatedly applies expression to second function while expression applied to first function returns truthy
pkg string imports a package from the local dpm folder
Clone this wiki locally