Standard library

October 20, 2016 · View on GitHub

Notation

In this document, the arguments of functions are a and b (with binary), function arguments of operators are f and g (with binary), and value arguments of operators are x and y (with binary). The first argument is south, the second is east. Monospace font is reserved for Jellyfish code. Lists are compared in lexicographical order, and atoms are strictly lower than lists. Any input combination not listed here is unimplemented, and for 0-threaded functions, list inputs are not listed either.

Functions

Threading levels are for unary a, binary a and binary b. Level -1 means no threading. A ' after an argument means that atomic arguments are converted to singleton lists.

SymbolNameArgumentsThreadingResultNotes
{Left identitya (any)-1a
a (any), b (any)-1, -1a
}Right identitya (any)-1a
a (any), b (any)-1, -1b
jRead valuea (any)-1Read STDIN and eval
jEval/unevala (atom), b (any)0, -1If a > 0, evaluate string b, otherwise convert b to stringIf a > 0, a multidimensional b is flattened before conversion
JRead stringa (any)-1Read STDIN as string
JRead charsa (any), b (atom)-1, 0Read b characters from STDINStops if EOF is encountered, reads entire STDIN if b < 0
pPrinta (any)-1Print a to STDOUT, return a
PMatrix printa (any)-1Print a to STDOUT in matrix format, return a
+Absa (atom)0abs(a)
Adda (atom), b (atom)0, 0a + b
-Negatea (atom)0-a
Subtracta (atom), b (atom)0, 0b - a
*Signuma (atom)0sign(a)
Multiplya (atom), b (atom)0, 0a * b
%Reciprocala (atom)01 / aReturn 0 for a = 0
Dividea (atom), b (atom)0, 0b / aReturn 0 for a = 0
``Rounda (atom)0round(a)
Modulusa (atom), b (atom)0, 0b mod aReturn 0 for a = 0
mFloora (atom)0floor(a)
Minimuma (any), b (any)-1, -1min(a, b)
MCeilinga (atom)0ceiling(a)
Maximuma (any), b (any)-1, -1max(a, b)
xPrime factorsa (atom)0Prime factors of a in ascending order
XORa (atom), b (atom)0, 0a xor b
bBase encodea (atom)0Base-2 digits of a
a (any), b (atom)1, 0Base-a digits of b
dBase decodea (any)1Digit(s) a as base-2 number
a (any), b (any)1, 1Digit(s) b as base-a number
=Equalitya (any), b (any)-1, -11 if a = b, otherwise 0
<Decrementa (atom)-1a - 1
Heada (list)-1First item of a
Less thana (any), b (any)-1, -11 if a < b, otherwise 0
>Incrementa (atom)-1a + 1
Taila (list)-1a with first item removed
Greater thana (any), b (any)-1, -11 if a > b, otherwise 0
^Squarea (atom)-1a2
Inita (list)-1a with last item removed
Powera (atom), b (atom)0, -1ba
Takea (atom), b (list)0, -1a items from bFrom beginning if a > 0, from end if a < 0
vSquare roota (atom)-1Square root of a
Lasta (list)-1Last item of a
Roota (atom), b (atom)0, -1b(1/a)
Dropa (atom), b (list)0, -1b with a items removedFrom beginning if a > 0, from end if a < 0
!Factoriala (atom)-1a!
Permutationsa (list)-1Permutations of a
Falling factoriala (atom), b (atom)0, -1b! / (b-a)!
K-permutationsa (atom), b (list)0, -1Length-a permutations of b
cCharactera (atom)0char(a)
Elementa (any), b' (list)-1, -11 if a occurs in b, otherwise 0
CPower of twoa (atom)-12a
Subsequencesa (list)-1Subsequences of a
Binomiala (atom), b (atom)0, -1b! / a!*(b-a)!
K-subsequencesa (atom), b (list)0, -1Length-a subsequences of b
nNumbera (atom)0num(a)
Intersectiona' (list), b' (list)-1, -1Intersection of a and b
uUniquesa' (list)-1uniques(a)
Uniona' (list), b' (list)-1, -1Union of a and b
NLogical negationa (any)-10 if a is truthy, 1 otherwise
List differencea' (list), b' (list)-1, -1a with items of b removed
#Lengtha (atom)-1Number of base-10 digits in a
a (list)-1Length of a
Repeata (atom), b' (list)-1, -1Each item of b repeated a times
Repeat/filtera (list), b' (list)-1, -1Each item of b repeated by the corresponding item of a
RReversea (atom)-1a
a (list)-1a reversed
Rotatea (atom), b (atom)0, -1b
a (atom), b (list)0, -1b rotated a steps to the left
kTo indicesa' (list)1Convert bitmask a to list of indices
KTo bitmaska' (list)1Convert list of indices a to bitmask
oOrdera' (list)-1a in increasing order
a' (list), b' (list)-1, -1b ordered using a as keysa is repeated or truncated to have b's length
rRangea (atom)-1Range from 0 to a-1From a+1 to 0 if a < 0
a (list)-1Cartesian product of ranges for atoms in a
a (any), b (any)-1, -1Range from a to b-1, or Cartesian product of ranges like above
,Flattena (any)-1flatten(a)
Concatenatea (any), b (any)-1, -1concatenate(a, b)
;Singletona (any)-1[a]
Paira (any), b (any)-1, -1[a, b]
$Shapea (any)-1Shape vector of a
Reshapea' (list), b (any)1, -1b reshaped according to shape vector a
@Indicesa (any)-1Indices of all atoms in a
Index intoa' (list), b (any)-2, -1Item of b at (multidimensional) index a
?Randoma (atom)-1Random number between 0 and aIf a = 0, random float between 0 and 1
a (list)-1Random permutation of a
a (atom), b (atom)1, -1a random elements between 0 and b in order
a (atom), b (list)1, -1a random elements of b in order
a (list), b (atom)1, -1Disjoint random subsequences of range(b), lengths given by a
a (list), b (list)1, -1Disjoint random subsequences of b, lengths given by a

Operators

In this table, threaded arguments are mentioned separately in the description.

SymbolNameOperator argsFunction argsResultNotes
_Callf (func)a (any)f(a)
a (any), b (any)f(a, b)
f (func), y (val)a (,b) (any)f(y)
x (val), g (func)a (,b) (any)g(x)
f (func), g (func)a (any)f(a)
a (any), b (any)f(a, b)
~Constantx (val)a (, b) (any)x
Flipf (func)a (any)f(a)
a (any), b (any)f(b, a)
Constantx (val), y (val)a (,b) (any)[x, y]
Curryf (func), y (val)a (,b) (any)f(a, y)
x (val), g (func)a (any)g(x, a)
a (any), b (any)g(x, b)
Flip composef (func), g (func)a (any)g(f(a))
Post-composea (any), b (any)f(g(a), g(b))
&Swap arityf (func)a (any)f(a, a)
a (any), b (any)f(b)
Bi-composef (func), y (val)a (any)f(f(y, a), y)
a (any), b (any)b → f(f(y, b), y) iterated a times
x (val), g (func)a (any)g(x, g(a, x))
a (any), b (any)b → g(x, g(b, x)) iterated a times
Composef (func), g (func)a (any)f(g(a))
Pre-composea (any), b (any)f(g(a, b))
(Left hookf (func)a (any)[f(a), a]
a (any), b (any)[f(a), b]
f (func), g (func)a (any)g(f(a), a)
a (any), b (any)g(f(a), b)
)Right hookf (func)a (any)[a, f(a)]
a (any), b (any)[a, f(b)]
f (func), g (func)a (any)f(a, g(a))
a (any), b (any)f(a, g(b))
[Left forkf (func)a (any)[f(a), a]
a (any), b (any)[f(a, b), b]
f (func), g (func)a (any)g(f(a), a)
a (any), b (any)g(f(a, b), b)
]Right forkf (func)a (any)[a, f(a)]
a (any), b (any)[a, f(a, b)]
f (func), g (func)a (any)f(a, g(a))
a (any), b (any)f(a, g(a, b))
`Threadx (val)a (,b) (any)~(x) threaded to level 0
f (func)a (,b) (any)f threaded to level 0
x (val), y (val)a (,b) (any)~(x) threaded to level(s) yy is reshaped to shape [3]
f (func), y (val)a (,b) (any)f threaded to level(s) yy is reshaped to shape [3]
x (val), g (func)a (,b) (any)g threaded to level(s) xx is reshaped to shape [3]
f (func), g (func)a (any)g(a), with g threaded to level(s) f(a)f(a) is reshaped to shape [3]
a (any), b (any)g(a, b), with g threaded to level(s) f(a, b)f(a, b) is reshaped to shape [3]
LLevelsx (val)a (any)Items of a of height x or greater
a (any), b (any)Items of a and b of height x or greater, paired together
f (func)a (any)f applied to atoms of a
a (any), b (any)f applied to atom-pairs of a and b
x (val), y (val)a (any)~(y) applied to items of a of height x or greater
a (any), b (any)~(y) applied to item-pairs of a and b of height x or greater
f (func), y (val)a (any)~(y) applied to items of a of height f(a) or greater
a (any), b (any)~(y) applied to item-pairs of a and b of height f(a, b) or greater
x (val), g (func)a (any)g applied to items of a of height x or greater
a (any), b (any)g applied to item-pairs of a and b of height x or greater
f (func), g (func)a (any)g applied to items of a of height f(a) or greater
a (any), b (any)g applied to item-pairs of a and b of height f(a, b) or greater
/Joinx (val)a (any)Join a x timesx threaded to level 0
a (any), b (any)Insert copies of a between items of b, and join x timesx threaded to level 0
Foldf (func)a (any)Fold f over a from the left
a (any), b (any)Fold f over b from the left with initial value a
Ifx (val), y (val)a (any)x if a is truthy, else y
a (any), b (any)[x, b] if a is truthy, else [y, b]
f (func), y (val)a (any)f(y) if a is truthy, else y
a (any), b (any)f(b) if a is truthy, else y
x (val), g (func)a (any)g(a) if f is truthy, else a
a (any), b (any)g(b) if f is truthy, else g(a)
f (func), g (func)a (any)g(a) if f(a) is truthy, else a
a (any), b (any)f(b) if a is truthy, else g(b)
\Substringsx (val)a (any)Substrings of a of length xx < 0 gives non-overapping substrings; x threaded to level 0
Selecta (any), b (any)Select item from a if x is even, from b if oddThreaded to level -2 for a and b, level 0 for x
Prefixesf (func)a (any)f(p) for every prefix p of a
Substringsa (any), b (any)f(s) for every length-a substring of ba threaded to level 0
Iteratef (func), y (val)a (any)Iterate f on a y timesy threaded to level 0
a (any), b (any)Iterate ~(a, f) on b y timesy threaded to level 0
x (val), g (func)a (any)Iterate g on a until x occurs, return each step
a (any), b (any)Iterate ~(a, g) on b until x occurs, return each step
f (func), g (func)a (any)Iterate f on a until g(a, f(a)) is truthy
a (any), b (any)Iterate ~(a, f) on b until g(b, f(a, b)) is truthy
OProductx (val)a (any)Cartesian product of a on level xx threaded to level 0
a (any), b (any)Cartesian product of choosing level-x elements from a or bx threaded to level 0
Eachf (func)a (any)f threaded to level -2
Tablea (any), b (any)f threaded to levels -2 and -1
ZReplace atx (val), y (val)a (any)a with elements at indices x replaced by corresponding items of y
a (any), b (any)b with elements at indices x replaced by corresponding items of y
f (func), y (val)a (any)a with elements at indices f(a) replaced by corresponding items of y
a (any), b (any)b with elements at indices f(a, b) replaced by corresponding items of y
x (val), g (func)a (any)a with elements at indices x replaced by corresponding items of g(a)
a (any), b (any)b with elements at indices x replaced by corresponding items of g(a, b)
f (func), g (func)a (any)a with elements at indices f(a) replaced by corresponding items of g(a)
a (any), b (any)b with elements at indices f(a, b) replaced by corresponding items of g(a, b)