AtFunctions.rb
Table of Contents
Function count: 344
Click on genres to show all functions in that genre.
((*) x) !in ([(*)] y) → bool (operator/logic)
Returns false if y contains x, otherwise true. See also: Has. Example
Print[3 !in 1:5]
?? false
Print[30 !in 1:5]
?? true((*) a) % ((*) b) → (*) (operator)
Vectorizes.
Modulo.' (fn func) → fn (unary operator)
Forces func to use parent scope. Example
a .= 5
Call[{ a .= 3 }]
Print[a]
?? 5
Call['{ a .= 93 }]
Print[a]
?? 93((*) a) * ((*) b) → (*) (operator)
Vectorizes.
Multiplication.((*) a) + ((*) b) → (*) (operator)
Vectorizes.
Addition.((*) a) - ((*) b) → (*) (operator)
Vectorizes.
Subtraction.(expr key) -> ((*) value) → ConfigureValue (operator)
Returns a ConfigureValue key-value pair of key and value. Used for configurable functions and hashes. ((*) obj) . (raw prop) → (*) (operator)
Obtains the member in obj with prop as a key. Note: this feature is not completely finished, and may have unintended behaviours, such as [1, 2, 3].size.
Example
ages := <~
john -> 32,
bob -> 14,
dude -> 92
~>
Print[ages.john]
?? 32
Person := Class! {
name .= _1
age .= _2
}
john := New[Person, "John Smith", 43]
Print[john.name, john.age, joiner->", "](number x) .. (number y) → [number] (operator)
Vectorizes.
Returns a range fromx to y, inclusive. (number x) ... (number y) → [number] (operator)
Vectorizes.
Returns a range fromx to y, excluding y. (number a) / (number b) → number (operator)
Vectorizes.
Dividesa by b. If a / b represents an integer, the argument becomes an integer. E.g., 4 / 2 is 2, not 2.0. (number|fn a) // (number b) → rational (operator)
Vectorizes.
Creates a fractiona / b. See also: Rational Arguments
fn a - Returns a function which, given e, returns Nest[a, e, b].
((*) x) /= ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x does not equal y, false otherwise. Note: does not call operator equality. (number|fn x) : (number|fn y) → [number]|fn (operator)
Vectorizes.
Returns a range fromx up to y. If x and y are both functions, returns a function f[...args] which calls x[...Map[y, args]]. Example
Print[3:6]
?? [3, 4, 5, 6]
add_rev := Add:Reverse
Print[add_rev[23, 45]]
?? 86(number x) :: (number y) → [number] (operator)
Vectorizes.
Returns a range fromx up to y. If x > y, returns a reversed range. Example
Print[3::6]
?? [3, 4, 5, 6]
Print[6::3]
?? [6, 5, 4, 3]
Print[-3::-6]
?? [-3, -4, -5, -6]((*) x) < ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x is less than y, false otherwise. ((*) x) <= ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x is less than or equal y, false otherwise. (fn x) <| ((*) y) → (*) (operator)
Calls x with single parameter y. ((*) x) = ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x equals y, false otherwise. ((*) x) =/= ((*) y) → bool (operator/logic)
Returns true if x does not equal y, false otherwise. ((*) x) == ((*) y) → bool (operator/logic)
Returns true if x equals y, false otherwise. ((*) x) > ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x is greater than y, false otherwise. ((*) x) >= ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x is greater than or equal to y, false otherwise. ((*) a) ^ ((*) b) → (*) (operator)
Vectorizes.
Exponentiation.([(*)]|fn a) ^^ ((*) b) → [(*)] (operator)
Removes all b from a. See also: Remove. If a is a fucntion, then folds a over b/ Example
Print[1:5 ^^ 2]
?? [1, 3, 4, 5]
Print[[1, 2, 2, 3, 2, 4, 5, 3, 2, 1, 3] ^^ 2]
?? [1, 3, 4, 5, 3, 1, 3]
Print[Add ^^ 1:5]
?? 15((*) a) | (fn|(*) b) → (*) (operator/logic)
Vectorizes.
Returnstrue if a divides evenly into b. Arguments
fn b - When b a function, calls b[a].
((*) x) |> (fn y) → (*) (operator)
Calls y with single parameter x. ([(*)] a) Ø ([(*)] b) → [(*)] (operator)
Returns the a without all elements of b. See also: Complement. (number x) ‥ (number y) → [number] (operator)
Vectorizes.
Returns a range fromx to y, inclusive. See also: ... (number x) … (number y) → [number] (operator)
Vectorizes.
Returns a range fromx to y, excluding y. See also: .... (number a) ⁄ (number b) → rational (operator)
Vectorizes.
Creates a fractiona / b. See also: Rational and //. (expr key) → ((*) value) → ConfigureValue (operator)
Returns a ConfigureValue key-value pair of key and value. See also: ->. ([(*)] a) ∆ ([(*)] b) → [(*)] (operator)
Returns the symmetric difference between a and b. ((*) a) ∧ ((*) b) → bool (operator/logic)
Returns true if both of a and b are truthy, false otherwise. Short-circuits. See also: and. ((*) a) ∨ ((*) b) → (*) (operator/logic)
Returns a if a is truthy, b otherwise. Short-circuits. See also: or. ([(*)] a) ∩ ([(*)] b) → [(*)] (operator)
Returns the intersection of a and b. ([(*)] a) ∪ ([(*)] b) → [(*)] (operator)
Returns the union of a and b. ((*) x) ≠ ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x does not equal y, false otherwise. See also: /=. ((*) x) ≤ ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x is less than or equal y, false otherwise. See also: <=. ((*) x) ≥ ((*) y) → bool (operator/logic)
Vectorizes.
Returnstrue if x is greater than or equal to y, false otherwise. See also: >=. ((*) a) ⊻ ((*) b) → bool (operator/logic)
Returns true if exactly one of a and b is truthy, false otherwise. See also: xor. ((*) a) ⊼ ((*) b) → bool (operator/logic)
Returns true if one of a and b are falsey, false otherwise. Short-circuits. See also: nand. ((*) a) ⊽ ((*) b) → bool (operator/logic)
Returns true if both of a and b are falsey, false otherwise. Short-circuits. See also: nor. Abs[number n] → number (numeric)
Vectorizes.
Calculates the absolute value ofn. Accumulate[[number] list] → [number] (list)
Generates the cumulative sums of list. Add[number ...args] → number (numeric)
Adds each of args together. Agenda[fn flist, fn[(*) -> number] cond, ...args] → fn[(*) -> (*)] (functional)
Curries.
Returns a functionfn[...args] such that the cond[...args]th element of flist is called upon args. Arguments
fn flist - A list of functions.
fn[(*) -> number] cond - A function which produces an index by which to obtain a function from flist.
Example
f := Agenda[ [Halve, {3 * _ + 1}], Odd]
Print[Map[f, [1, 2, 3, 4]]]
?? [4, 1, 10, 2]All[fn|[(*)] f, [(*)] list?] → bool (logic)
Returns true if all members of Map[f, list] are truthy. Arguments
[(*)] list? - When omitted, returns true if all members of f are truthy. Otherwise, returns false. When specified, f must be a function.
AllInput[] → string (IO)
Reads all input from the instance's source input. And[(*) a, (*) b] → bool (logic)
Logical conjunction. Returns true if both a and b are truthy, false otherwise. Example
Print[TruthTrablePretty["And", 2]]
?? A | B | And[A, B]
?? ---+---+-----------
?? 0 | 0 | 0
?? 0 | 1 | 0
?? 1 | 0 | 0
?? 1 | 1 | 1((*) a) and ((*) b) → bool (operator/logic)
Returns true if both of a and b are truthy, false otherwise. Short-circuits. Any[fn|[(*)] f, [(*)] list?] → bool (logic)
Returns true if any member of Map[f, list] is truthy. Arguments
[(*)] list? - When omitted, returns true if any member of f is truthy. Otherwise, returns false. When specified, f must be a function.
Applier[fn func] → fn[[(*)]] (functional)
Returns a function fn[...args] which applies func to args. Example
f := Applier[Print]
f[1:5]
Print[1, 2, 3, 4, 5]
?? 1 2 3 4 5Apply[fn func, [(*)] arg_arr] → (*) (functional)
Calls func with arg_arr. Example
args := [ Reverse, [ "hello", "world" ] ]
Print[ Apply[Map, args] ]
?? ["olleh", "dlrow"]ArcCos[number n] → number (numeric/trig)
Vectorizes.
Calculates .ArcCosh[number n] → number (numeric/trig)
Vectorizes.
Calculates .ArcSin[number n] → number (numeric/trig)
Vectorizes.
Calculates .ArcSinh[number n] → number (numeric/trig)
Vectorizes.
Calculates .ArcTan[number n] → number (numeric/trig)
Vectorizes.
Calculates .ArcTan2[number y, number x] → number (numeric/trig)
Vectorizes.
Calculates the principal value of , oratan2(y, x). ArcTanh[number n] → number (numeric/trig)
Vectorizes.
Calculates .Arg[number n=0] → string (IO)
Returns the nth argument given to the program. ArrayFlatten[[[list]] list] → [list] (list/matrix)
Flattens the matrices held in the matrix-like list. Example
m1 := [[1, 2], [3, 4]]
m2 := [[0, 0], [7, 7]]
Display[ArrayFlatten[ [[m1, m2, m1], [m2, m1, m2]] ]]
?? 1 2 0 0 1 2
?? 3 4 7 7 3 4
?? 0 0 1 2 0 0
?? 7 7 3 4 7 7Average[[number] list] → number (list)
Returns the average of list, that is, the sum of the elements divided by the length. Bin[number n] → number (numeric/bases)
Vectorizes.
Convertsn to base 2. Bisect[[(*)] list, **opts] → [[(*)], [(*)]] (list)
Splits list in half. Options
bias → what should be done with the center element, in the case of odd lists. "none": drop it (default). "left": append center to the left half. "right": append center to the right half.
Example
Print[Bisect[1:4]]
?? [[1, 2], [3, 4]]
Print[Bisect[1:5]]
?? [[1, 2], [4, 5]]
Print[Bisect[1:5, bias->$none]]
?? [[1, 2], [4, 5]]
Print[Bisect[1:5, bias->$left]]
?? [[1, 2, 3], [4, 5]]
Print[Bisect[1:5, bias->$right]]
?? [[1, 2], [3, 4, 5]]Bond[fn func, (*) larg] → fn (functional)
Bonds larg to the left side of func. That is, Bond[func, larg][...args] is the same as func[larg, ...args]. Bounce[[(*)] list] → [(*)] (list)
Reforms result.
"Bounces" a list. That is, returns the list concatenated with itself reversed, where the last element of the original array is not duplicated in the concatenation. Inspiration: Jelly'sŒB monadic atom. Example
Print[Bounce[1:3]]
?? [1, 2, 3, 2, 1]
Print[Bounce["Hello"]]
?? HellolleH
Print[Bounce[942]]
?? 94249C[(*) arg] → fn (functional)
Returns a function that returns arg. Call[fn f, (*) ...args] → (*) (functional)
Calls f over args. Example
Call[Print, "Hello", "World"]
?? Hello WorldCallEach[[fn] fs, (*) ...args] → (*) (functional)
Curries.
Vectorizes function calling over each functionf in fs over args. CallN[fn f, number n, (*) ...args] → (*) (functional)
Curries.
Callsf n times over args, storing the results in a list. Example
rand := Configure[Random, RNG->RNG[10]]
Print[CallN[Random, 4, 3, 10]]
?? [4, 8, 7, 10]
Print[CallN[rand, 10, 0, 1]]
?? [1, 1, 0, 1, 0, 1, 1, 0, 1, 1]Cbrt[number n] → number (numeric)
Vectorizes.
Returns the cube root ofn. Ceiling[number n, number r?] → number (numeric)
Vectorizes.
Returnsn rounded up to the nearest integer. Arguments
number r? - the precision to round. No precision if omitted.
Center[[(*)] ent, number amt, (*) pad?] → string (string)
Vectorizes.
Centersent to amt elements, padding with pad. Arguments
(*) pad? - Default: " " or 0, depending on ent.
Example
Print[Center["a", 3]]
?? " a "
Print[Center[[1, 2], 6]]
?? [0, 0, 1, 2, 0, 0]
Print[Center["Hi!", 10, "~"]]
?? "~~~Hi!~~~~"
Print[Center[9, 5, 1]]
?? 11911Char[number|[number] arg] → string (conversion)
Converts arg to characters. Arguments
number arg - Converts arg to a character.
[number] arg - Converts arg to a string of char codes.
Chars[string str] → [string] (string)
Vectorizes.
Returns the characters ofstr. Chomp[(*) ent, (*) to_chomp=NOT_PROVIDED] → (*) (string)
Removes to_chomp once from the end of ent. Arguments
(*) to_chomp=NOT_PROVIDED - For strings, defaults to "\n"; otherwise, 0.
Chop[[(*)] list, size, **opts] → [[(*)]] (list)
Reforms result's elements.
Chopslist into groups of length size. Options
extra → Boolean: keeps elements which don't add up to size if true. Default: true.
Example
Print[Chop[1:8, 3]]
?? [[1, 2, 3], [4, 5, 6], [7, 8]]
Print[Chop[1:8, 3], extra->false]
?? [[1, 2, 3], [4, 5, 6]]
Print[Chop["Hello, World!", 3]]
?? ["Hel", "lo,", " Wo", "rld", "!"]
Print[Chop[1:12, [1, 2, 3]]]
?? [[1], [2, 3], [4, 5, 6], [7], [8, 9], [10, 11, 12]]Chunk[[(*)] list, fn f?] → [[(*), [(*)]]] (list)
Chunks list into runs of consecutive values. Returns an array of members which look like [el, els], where el is the principal run value, and els are the values in that run. Arguments
fn f? - When specified, maps each value el in list over f, then uses f[el] as the principal run value.
Example
Print[Chunk[ [1, 2, 3, 2, 2, 3] ]]
?? [[1, [1]], [2, [2]], [3, [3]], [2, [2, 2]], [3, [3]]]
Display[Chunk[ [1, -1, 1, 1, 2, 3, -3, 5, -2 ], Square ]]
?? 1 [1, -1, 1, 1]
?? 4 [2]
?? 9 [3, -3]
?? 25 [5]
?? 4 [-2]Class[fn body, parent=nil] → class (class)
Creates an anonymous class. Arguments
fn body - Any local definition made within constitutes a method or instance variable decleration.
ClassNamed[string name, parent=nil] → fn (class)
Creates a named class. Returns a function which acts similarly to Class. Clear[string name] → (*) (scope)
Undefines name from the global scope. Returns that variable's value, or nil if the variable was undefined. ClearLocal[string name] → (*) (scope)
Undefines name from the local scope. Returns that variable's value, or nil if the variable was undefined. ClearScreen[] → nil (IO)
Clears the console's screen. Cls[] → bool (IO)
Clears the console screen. Returns `true` if successful, `false` otherwise. Collapse[[(*)] ...lists] → [(*)] (list)
Concatenates all the lists in lists, except for matching prefix-suffix pairs. Collatz[number n] → [number] (numeric/series)
Vectorizes.
Produces the Collatz sequence ofn. CollatzSize[number n] → number (numeric/series)
Vectorizes.
Returns the number of steps it takes forn to reach 1 according to the Collatz transformation. Complement[[(*)] parent, [(*)] ...args] → [(*)] (list)
Returns all elements of parent not included in any of the lists in args. Concat[[(*)] ...args] → [(*)] (list)
Returns the concatentation of each list in args. Example
Print[Concat[ 1:5, 2:3, [7], [[8, 9]] ]]
?? [1, 2, 3, 4, 5, 2, 3, 7, [8, 9]]Configurable[fn f] → fn (functional)
Gives f access to any options passed to it, i.e. through GetOption. Example
nameOf := Configurable { GetOption[$name] }
Print[nameOf[name -> "John"]]
?? John
Print[nameOf[]]
?? nilConfigure[fn func, **opts] → fn (functional)
Returns a function which calls func configured with opts. Example
print_weird := Configure[
Print,
joiner->", ",
before->"{",
after->"}\n"
]
print_weird[3, 4, 5]
?? {3, 4, 5}Cos[number n] → number (numeric/trig)
Vectorizes.
Calculates .Cosh[number n] → number (numeric/trig)
Vectorizes.
Calculates .Count[fn|(*) f, [(*)] list] → number (list)
Curries.
Counts the number of members satisfyingf in list; or, if f is not a function, the number of times f appears in list. Curry[fn f, number arity?] → fn (functional)
Returns fn, fully curried according to arity. Arguments
number arity? - Default: #f.
Example
add_dy := [x, y] -> { x + y }
adder := Curry[add_dy]
add3 := adder[3]
Print[add3[5]]
?? 8
Print[adder[2][5]]
?? 7
add_tri := Curry[Add/3]
adder1 := add_tri[1]
add6 := adder1[5]
Print[add6[10]]
?? 16Decreasing[[(*)] list] → bool (list/logic)
Returns true if every element a which is followed by an element b is strictly greater than b. Example
Print[Decreasing[ -(1:5) ]]
?? true
Print[Decreasing[ [2, 1, 0] ]]
?? true
Print[Decreasing[ [] ]]
?? true
Print[Decreasing[ [2, 2, 1, 0] ]]
?? false
Print[Decreasing[ 1:5 ]]
?? falseDefine[string name, (*) value] → (*) (scope)
Defines name in the global scope as value. Returns value. Example
Define[$a, "This is variable a!"]
Print[a]
?? This is variable a!Delta[[number] list] → [number] (list)
Returns the differences between each member of list. Example
Print[Delta[ 1:4 ]]
?? [1, 1, 1]
Print[Delta[ [] ]]
?? []
Print[Delta[ Square[0:4] ]]
?? [1, 3, 5, 7]Denominator[number n] → number (numeric/rational)
Vectorizes.
Returns the numerator ofn. Difference[[(*)] a, [(*)] b] → [(*)] (list)
Returns all elements exclusive to a or b. Digits[number n] → [number] (numeric)
Vectorizes.
Produces the digits ofn. Display[(*) ent] → (*) (IO)
Displays ent in a human-reversible format. Primarily, prints the elements of arrays (whose dimension is at least 2) on separate lines. Example
Display[ [1:3, 4:6, 9:11] ]
?? 1 2 3
?? 4 5 6
?? 9 10 11
Display[ "Hello, World!" ]
?? "Hello, World!"Divide[number ...args] → number (numeric)
Divides each number in args by the next. That is, folding division over args DivMod[number d, number m] → [number, number] (numeric)
Vectorizes.
Simultaneously calculates division and modulus operations, returned as a pair.Example
Print[DivMod[23, 2]]
?? [11, 1]
Print[DivMod[5, 20]]
?? [0, 5]Double[number n] → number (numeric)
Vectorizes.
Doublesn. DoWhile[expression cond, expression body] → (*) (logic)
Evaluates body, then stops only if cond evaluates as falsey. Example
i := 0
DoWhile[i < 5, Print[i]; i := i + 1]
?? 0
?? 1
?? 2
?? 3
?? 4
DoWhile[false, Print["Hello!"]]
?? Hello!Downcase[string str] → string (string)
Vectorizes.
Replaces all uppercase letters instr with the respective lowercase one. Example
Print[Downcase["Hello, World!"]]
?? hello, world!
Print[Downcase[">>> NO ONE"]]
?? >>> no one
Print[Downcase["le monde"]]
?? le monde((*) a) else ((*) b) → bool (operator/logic)
Returns a if a is truthy, b otherwise. Short-circuits. Enumerate[[(*)] list, start=0] → [[(*), number]] (list)
Returns a list of all elements in list paired with their indices, starting at offset. Eval[string str] → (*) (meta)
Evaluates str in a new scope. Returns the last expression evaluated. EvalHere[string str, blanks=[]] → (*) (meta)
Evaluates str in a the current scope. Returns the last expression evaluated. Even[number n] → bool (numeric/logic)
Vectorizes.
Returnstrue if n is even (a multiple of 2), otherwise false. Exit[number code?] → nil (IO)
Terminates the program with exit code 0. Flushes STDOUT. Arguments
number code? - the code to exit with.
Exp[number n] → number (numeric)
Vectorizes.
Calculates .F[BigDecimal|complex|(*) ent] → number (conversion)
Converts ent to a floating-point number. Arguments
BigDecimal ent - Obtains the floating point value of ent.
complex ent - Forces each component of ent to be a floating point number.
(*) ent - Calls N[ent], then converts to that float.
Fibonacci[number n] → number (numeric/series)
Vectorizes.
Returns thenth number in the Fibonacci sequence, starting with f0 = 0 and f1 = 1. FileExists[string name] → bool (IO/files)
Returns true if name represents a valid file, false otherwise. FileRead[string name, **opts] → string (IO/files)
Returns the contents of file name, or nil if the file does not exist. Options
encoding → The encoding that the target file is in.
FileWrite[string name, string content, **opts] → number (IO/files)
Writes content to file name. Returns the number of bytes written. Options
encoding → The encoding that the target file is in.
Find[fn|(*) f, [(*)] list] → (*) (list)
Returns the first element e in list which satisfies f. Returns nil otherwise. Arguments
fn f - applied to each successive member of list until a truthy value is obtained.
(*) f - returns the first element in list equal to f.
FindHead[[string]|{string->(*)} opts, string val] → string (string)
Selects the first key (or value) in opts which start with val. Example
names := ["John", "James", "Mary"]
Print[FindHead[names, "J"]]
?? John
Print[FindHead[names, "Ja"]]
?? James
Print[FindHead[names, "M"]]
?? Mary
Print[nil = FindHead[names, "Z"]]
?? true
options := <~
stop -> 0,
continue -> 1,
redo -> 2
~>
choice := "s"
Print[FindHead[options, choice]]
?? stopFirst[[(*)] list] → (*) (list)
Returns the first element of list. Example
Print[First[ [3, 9, 2, 0] ]]
?? 3
Print[First[ "Hello!" ]]
?? HFixpoint[fn f, (*) n] → (*) (functional)
Curries.
Appliesf to n until f[n] converges. Flat[[(*)] list, number n?] → [(*)] (list)
Flattens list. Arguments
number n? - when specified, flattens list to 1 level n times.
FlatGet[[(*)] list, [(*)]|(*) inds] → (*) (list)
Returns list[i0][i1]...[iN] for each i in inds. Example
id := Identity[3]
Display[id]
?? 1 0 0
?? 0 1 0
?? 0 0 1
Print[FlatGet[id, 0]]
?? [1, 0, 0]
Print[FlatGet[id, [0]]]
?? [1, 0, 0]
Print[FlatGet[id, [0, 0]]]
?? 1Flip[[(*)] list] → [(*)] (list)
Reforms result.
Reverses and transposes a list, or, if the list has only one dimension, reverses it.Floor[number n, number r?] → number (numeric)
Vectorizes.
Returnsn rounded down to the nearest integer. Arguments
number r? - the precision to round. No precision if omitted.
Fold[fn f, [(*)] list, (*) start?] → (*) (functional/list)
Curries.
Folds the functionf over the list list, optionally starting with start. Example
Print[Fold[${ x + y }, [2, 3, 6, 7]]]
?? 18
Print[Fold[${ $"f[${x}, ${y}]" }, 1:5]]
?? f[f[f[f[1, 2], 3], 4], 5]
Print[Fold[Add, 123]]
?? 6
Print[Fold[${ y + x }, "Hello, World!"]]
?? !dlroW ,olleH
Print[Fold[Add, [1]]]
?? 1
Display[Fold[Add, []]]
?? nil
Display[Fold[Add, [], 0]]
?? 0FoldList[fn f, [(*)] ent, (*) start?] → [(*)] (functional/list)
Curries.
Cumulatively folds the functionf over ent, optionally starting at start. FoldRight[fn f, [(*)] list, (*) start?] → (*) (functional/list)
Curries.
Folds the functionf over the list list, optionally starting with start. Example
Print[Fold[${ x + y }, [2, 3, 6, 7]]]
?? 18
Print[Fold[${ $"f[${x}, ${y}]" }, 1:5]]
?? f[f[f[f[1, 2], 3], 4], 5]
Print[Fold[Add, 123]]
?? 6
Print[Fold[${ y + x }, "Hello, World!"]]
?? !dlroW ,olleH
Print[Fold[Add, [1]]]
?? 1
Display[Fold[Add, []]]
?? nil
Display[Fold[Add, [], 0]]
?? 0FoldRightList[fn f, [(*)] ent, (*) start?] → [(*)] (functional/list)
Curries.
Cumulatively folds the functionf over ent from the right, optionally starting at start. ForEach[[(*)] ent, body] → nil (logic)
For every value el in ent, evaluates body, setting the first abstract value to el, and the second to its index. Fork[fn f, fn g, fn h] → fn (functional)
Composes the functions f, g, and h into a fork. When called with arguments args, this is equivalent to calling g[f[...args], h[...args]]. Example
avg := Fork[Sum, Divide, Size]
Print[avg[1:5]]
?? 3.0Format[string str, (*) ...args] → string (string)
Formats a string. Currently, uses Ruby's % method on strings. Example
Print[Format["%s is a %s", "Java", "Joke"]]
?? Java is a JokeFromBase[[number] num, number base] → number (numeric/bases)
Vectorizes.
Convertsnum from base base to base 10. Arguments
[number] num - an array of digits representing the number in base base.
number base - a number greater than 0, representing the source base of the numeric array.
GCD[number ...args] → number (numeric)
Takes the Greatest Common Divisor of the atoms of args. Arguments
number ...args - List of numbers, which can have nested elements.
GenerateFirst[fn f, fn cond, number start?] → (*) (functional)
Starting at n = start, increments n until cond[f[n]] is truthy. Returns f[n]. Note: this ignores nil values returned. Arguments
fn f - A function that maps a number to a domain, such as Square or Prime.
fn cond - A function which, given a possible result of f, returns a truthy or falsey value.
number start? - The starting point for testing numbers.
GenerateN[fn f, fn cond, number size, number start?] → (*) (functional)
Similar to GenerateFirst, returns the first size values of f satisfying cond Arguments
fn f - A function that maps a number to a domain, such as Square or Prime.
fn cond - A function which, given a possible result of f, returns a truthy or falsey value.
number start? - The starting point for testing numbers.
Get[[(*)] list, number|ConfigureValue ind] → [(*)]|string (list)
Vectorizes.
Gets all members at indicesinds from list. Arguments
ConfigureValue ind - Returns the members between the key and the value. If the value is negative, starts at the respective index from the right. Returns a string if given a string, instead of an array of characters.
Example
Print[Get[1:5, 2]]
?? 3
Print[Get["Hello, World!", 0:4]]
?? ["H", "e", "l", "l", "o"]
Print[Get["Hello, World!", 4 -> -4]]GetOption[string name, (*) ...others] → (*) (functional)
Gives the function easy access to the OPTIONS variable, if defined. If the requested option was not passed, the first non-nil element in others will be returned, if any. Example
calibrate := Configurable {
sens .= GetOption[$sensitivity, 0.01]
If[_ <= sens,
"no reading",
$"reading: ${_ * sens}"
]
}
Print[calibrate[5]]
?? reading: 0.05
Print[calibrate[5, sensitivity->100]]
?? no readingGrade[[(*)] list] → [number] (list)
Returns a list of indices such that, when list is indexed by that list, the result is list sorted. Grid[string str, string inner?] → string (string)
Returns the characters of each line of str. Arguments
string inner? - Character to pad the ends of each line with. Default: " ".
Example
Map[Print, Grid["Hello,\nWorld\nof mine!"]]
?? ["H", "e", "l", "l", "o", ",", " ", " "]
?? ["W", "o", "r", "l", "d", " ", " ", " "]
?? ["o", "f", " ", "m", "i", "n", "e", "!"]Group[fn f, [(*)] list] → Hash[(*) -> (*)] (list)
Curries.
Groupslist according to Map[fn, list]. Halve[number n] → number (numeric)
Vectorizes.
Takes half ofn. Has[[(*)]|string list, (*) member] → bool (list)
Returns true if list contains member, false otherwise. Arguments
string list - returns if member is contained within list.
Hash[ConfigureValue ...opts] → Hash[string -> (*)] (data)
Creates a hash. Arguments
ConfigureValue ...opts - A series of value pairs a -> v.
Hex[number n] → number (numeric/bases)
Vectorizes.
Convertsn to base 16. Hook[fn f, fn g] → fn (functional)
Composes the functions f and g into a hook. When called with arguments args this is equivalent to calling f[First[args], g[...args]]. HTMLEscape[string str] → string (string/HTML)
Escapes str such that it is safe to be passed to an HTML document. (Escapes the following: &<>".) Id[(*) a] → (*) (functional)
Identity function; returns its argument. If[(*) cond, expression t, expression f?] → (*) (logic)
If cond is truthy, evaluates t. Otherwise, if f is specified, evaluates f. Example
If[3 = 4,
Print["Logic does not hold!"],
Print["Everything is situation normal."]
]Im[(*) n] → number (numeric)
Vectorizes.
Returns the imaginary part ofn, or 0 if it doesn't exist. Imaginary[number n] → bool (numeric/logic)
Vectorizes.
Returnstrue if n = a+bi for b /= 0, otherwise false. ((*) x) in ([(*)] y) → bool (operator/logic)
Returns true if y contains x, otherwise false. See also: Has. Example
Print[3 in 1:5]
?? true
Print[30 in 1:5]
?? falseIncreasing[[(*)] list] → bool (list/logic)
Returns true if each member el is strictly greater than the previous element, otherwise false. Index[[(*)] list, (*) ind] → number (list)
Vectorizes.
Returns the index of the first occurrence ofind in list. IndexFlat[[(*)] list, (*) ind] → number (list)
Returns the index of the first occurrence of ind in list. Indices[[(*)] list, (*) ind] → [number] (list)
Vectorizes.
Returns all indices at whichind occurs in list. Example
Print[Indices[ [1, 1, 2, 3, 1, 3, 1], [1, 3] ]]
?? [[0, 1, 4, 6], [3, 5]]IndicesFlat[[(*)] list, (*) ind] → [number] (list)
Returns all indices at which ind occurs in list. Example
Print[IndicesFlat[ [1, 1, 2, 3, 1, 3, 1], [1, 3] ]]
?? []Integers[...args] → [(*)] (list)
Returns the first Prod[Size => args] non-negative integers. Integral[number n] → bool (numeric/logic)
Vectorizes.
Returnstrue if n represents an integer, otherwise false. Intersection[[(*)] ...lists] → [(*)] (list)
Returns the intersection of the arguments. Intersperse[[(*)] list, (*) joiner] → [(*)] (list)
Returns a list where joiner is placed in between each element of list. Example
Print[Intersperse[1:3, 0]]
?? [1, 0, 2, 0, 3]IntLog[number n, base] → number (numeric)
Vectorizes.
Calculates the discrete logarithm ofn mod base. Invariant[fn func, (*) arg?] → bool (logic)
Determines whether or not arg = func[arg] Arguments
(*) arg? - when omitted, returns a function f[x] = Invariant[func, x].
InvocationIndex[fn func] → fn (functional)
Given a function func, returns a function which calls func with an additional argument representing the number of times func has been invoked. Iota[[(*)]|number min] → [(*)] (list)
Returns an range from 0 (inclusive) to min or the length of min as applicable (exclusive). Example
Print[Iota[5]]
?? [0, 1, 2, 3, 4]
Print[Iota["Hi!"]]
?? [0, 1, 2]((*) el) is_a (class klass) → bool (operator/logic)
Returns true if el is an instance of klass, otherwise false. ((*) el) is_an (class klass) → bool (operator/logic)
Returns true if el is an instance of klass, otherwise false. ((*) el) is_not_a (class klass) → bool (operator/logic)
Returns false if el is an instance of klass, otherwise true. ((*) el) is_not_an (class klass) → bool (operator/logic)
Returns false if el is an instance of klass, otherwise true. IsComposite[number n] → bool (numeric/prime)
Vectorizes.
Returnstrue if n is composite (not prime), and false otherwise. IsImaginary[number n] → bool (numeric/logic)
Returns true if n = a+bi for b /= 0, otherwise false. IsPrime[number n] → bool (numeric/prime)
Vectorizes.
Returnstrue if n is prime, and false otherwise. IsSquare[number n] → bool (numeric/logic)
Returns true if n is a perfect square (i.e. expressable as an integer multiplied by itself), otherwise false. Join[[(*)] list, string joiner?] → string (string)
Vectorizes.
Joinslist by joiner. Larger[[(*)] a, [(*)] b] → (*) (list)
Vectorizes.
Returns the larger ofa and b. Similar to Max, except Larger vectorizes. Example
Print[Larger[1, 5]]
?? 5
Print[Larger[[1, 2, 3], [3, 2, 1]]]
?? [3, 2, 3]Last[[(*)]|string list] → (*) (list)
Returns the last member of list. Example
Print[Last["hiya"]]
?? a
Print[Last[1:5]]
?? 5LastIndex[[(*)] list, (*) ind] → number (list)
Vectorizes.
Returns the index of the last occurrence ofind in list. LastIndexFlat[[(*)] list, (*) ind] → number (list)
Returns the index of the last occurrence of ind in list. LCM[number ...args] → number (numeric)
Takes the Least Common Multiple of the atoms of args. Arguments
number ...args - List of numbers, which can have nested elements.
Lines[string str] → [string] (string)
Vectorizes.
Returns all lines ofstr; splits on line breaks, which are newlines preceeded by an optional carriage reutrn. Example
Print[Lines["abc\nhello"]]
?? ["abc", "hello"]List[(*) ent] → [(*)] (list)
Forces ent into a list. Arguments
number ent - Returns the digits of ent.
string ent - Returns the characters of ent.
hash ent - Returns an array of key-value pairs in ent.
Ln[number n] → number (numeric)
Vectorizes.
Takes the natural logarithm ofn. Note that . Local[string name, (*) value] → (*) (scope)
Defines name in the local scope as value. Returns value. Log[number n] → number (numeric)
Vectorizes.
Takes the base-10 logarithm of n. Log2[number n] → number (numeric)
Vectorizes.
Takes the base-2 logarithm of n. LogBase[number n, b] → number (numeric)
Vectorizes.
Takes the base-b logarithm of n. LowerTriangle[[[(*)]] mat, bool strict?] → [[(*)]] (list/matrix)
Returns the lower triangle of mat, where the remaining values are replaced with zeroes. Arguments
bool strict? - If true, includes the diagonal. Default: true.
Example
mat := Integers[3, 3] + 1
Display[mat]
?? 1 2 3
?? 4 5 6
?? 7 8 9
Display[LowerTriangle[mat]]
?? 1 0 0
?? 4 5 0
?? 7 8 9
Display[LowerTriangle[mat, true]]
?? 0 0 0
?? 4 0 0
?? 7 8 0Mask[[(*)] mask, [(*)] list] → [(*)] (logic)
Reforms result.
Selects all elementsel in list whose respective member in mask is truthy. Example
Print[Mask[ [true, false, true, true, false], 1:5]]
?? [1, 3, 4]Match[string source, (*) match] → string (string/regex)
Vectorizes.
Matches first occurrence ofmatch (cast to regex) in source. If only one argument source is given, then returns a function which takes the source as input. Example
Print[Match["no you?", ".{3}"]]
?? "no "
Print[Match["cat in the hat", "[ch]at"]]
?? "cat"
match2vowels := Match[`"\w*[aeiou]{2}\w*"]
Print[match2vowels["Hello, loopy man!"]]
?? "loopy"MatchAll[string source, (*) match] → [(*)] (string/regex)
Vectorizes.
Matches all occurrences ofmatch in source. Example
Print[MatchAll["no you?", ".{3}"]]
?? ["no ", "you"]
Print[MatchAll["cat in the hat", "[ch]at"]]
?? ["cat", "hat"]
match2vowels := MatchAll[`"\w*[aeiou]{2}\w*"]
Print[match2vowels["Hello, loopy man!"]]
?? ["loopy"]Max[(*) ...args] → (*) (list)
Returns the largest element contained in any atom of args. Median[[number] list] → number (list)
Returns the median of list. Example
Print[Median[[1, 2, 3]]]
?? 2
Print[Median[[1, 2, 3, 4]]]
?? 2.5Min[(*) ...args] → (*) (list)
Returns the smallest element contained in any atom of args. Modify[string head, expression body] → (*) (scope)
Modifies head according to body. Arguments
expression body - an expression using the first abstract variable _ to represent the original value.
Example
a := 3
Modify[$a, _ * 2 + 1]
Print[a]
?? 7Multiply[number ...args] → number (numeric)
Takes the product of the elements of args. N[[number]|string|number|(*) ent] → number (conversion)
Converts ent to an number. Arguments
[number] ent - Converts ent to base 10.
string ent - Parses ent as a base 10 integer.
number ent - Converts ent to an integer if it represents one.
(*) ent - Attempts to cast ent to an integer.
Nand[(*) a, (*) b] → bool (logic)
Logical alternative denial. Returns true if at least one of a and b are falsey, false otherwise. Example
Print[TruthTrablePretty["Nand", 2]]
?? A | B | Nand[A, B]
?? ---+---+------------
?? 0 | 0 | 1
?? 0 | 1 | 1
?? 1 | 0 | 1
?? 1 | 1 | 0((*) a) nand ((*) b) → bool (operator/logic)
Returns true if one of a and b are falsey, false otherwise. Short-circuits. Needs[string ...libs] → [string] (meta)
Imports libraries. Returns list of libaries' names included. Arguments
string ...libs - list of strings corresponding to library names.
Negative[number n] → bool (numeric/logic)
Vectorizes.
Returnstrue if n is less than 0, otherwise false. Nest[fn f, init, number n] → (*) (functional)
Applies f to init n times. Example
Print[Nest[Double, 1, 3]]
?? 8 (= 2 ^ 3)NestList[fn f, init, number n, **opts] → (*) (functional)
Applies f to init n times, keeping the intermediate results. Options
first → Specifies whether or not to include the first element. Default: true.
Example
Print[NestList[Double, 1, 3]]
?? [1, 2, 4, 8]
Print[NestList[Double, 1, 3, first->false]]
?? [2, 4, 8]NestListWhile[fn f, fn cond, (*) init, **opts] → (*) (functional)
Applies f to init until cond[init] is truthy. Options
first → whether or not the input element init is included as the first element in the results. Default: true.
Example
Print[NestListWhile[Halve, Even, 100]]
?? [100, 50, 25]NestWhile[fn f, fn cond, (*) init] → (*) (functional)
Curries.
Appliesf to init until cond[init] is truthy. Example
Print[NestWhile[Halve, Even, 100]]
?? 25New[class ac, (*) ...args] → class[] (class)
Instantiates a class with parameters args. NextPrime[number n, number rep?] → number (numeric/prime)
Vectorizes.
Returns the next prime greater thann. Arguments
number rep? - When specified, returns the repth prime after n.
None[fn|[(*)] f, [(*)] list?] → bool (logic)
Returns Not[Any[...]]. Arguments
[(*)] list? - When omitted, returns true if any member of f is truthy. Otherwise, returns false. When specified, f must be a function.
((*) a) nor ((*) b) → bool (operator/logic)
Returns true if both of a and b are falsey, false otherwise. Short-circuits. Nor[(*) a, (*) b] → bool (logic)
Logical joint denial. Returns true if at both a and b are falsey, false otherwise. Example
Print[TruthTrablePretty["Nor", 2]]
?? A | B | Nor[A, B]
?? ---+---+-----------
?? 0 | 0 | 1
?? 0 | 1 | 0
?? 1 | 0 | 0
?? 1 | 1 | 0not ((*) arg) → bool (unary operator)
Returns false if b is truthy, true otherwise. ((*) a) not ((*) b) → bool (operator/logic)
Returns false if b is truthy, a otherwise. Example
even_nonpos := { Even[_] not Positive[_] }
Print[Select[even_nonpos, [-4, -3, -2, 0, 2, 3, 4]]]
?? [-4, -2, 0]Numerator[number n] → number (numeric/rational)
Vectorizes.
Returns the numerator ofn. Numeric[number n] → bool (numeric/logic)
Returns true if n is a numeric value, otherwise false. Oct[number n] → number (numeric/bases)
Vectorizes.
Convertsn to base 8. Odd[number n] → bool (numeric/logic)
Vectorizes.
Returnstrue if n is odd (not a multiple of 2), otherwise false. On[fn|[number] cond, fn f, [(*)] arr] → [number] (functional)
Curries.
Appliesf to indices of arr, selected by cond. Arguments
fn cond - If the given index yields true over cond, then the respective element is mapped to f.
[number] cond - If the given index is a member of cond.
Example
on_second := On[Odd]
rev_second := on_second[Reverse]
Print[rev_second[[
[1, 2, 3],
[4, 5, 6],
["a", "b", "c"],
["d", "e", "f"]
]]]
?? [[1, 2, 3], [6, 5, 4], ["a", "b", "c"], ["f", "e", "d"]]Option[string prompt, **opts] → string (IO)
Prints prompt and waits for character input found in opts. Example
input := Option["Press something!",
s -> "stop this program",
i -> "print info",
h -> "print hello world"
]
?? outputs "Press something!"
?? user presses the `i` key
Print["Received:", Repr[input]]
?? Received: "i"Or[(*) a, (*) b] → bool (logic)
Logical disjunction. Returns true if at least one of a and b are truthy, false otherwise. Example
Print[TruthTrablePretty["Or", 2]]
?? A | B | Or[A, B]
?? ---+---+----------
?? 0 | 0 | 0
?? 0 | 1 | 1
?? 1 | 0 | 1
?? 1 | 1 | 1((*) a) or ((*) b) → (*) (operator/logic)
Returns a if a is truthy, b otherwise. Short-circuits. Ord[string|number ent, number offset?] → number (string)
Vectorizes.
Returns the UTF-8 ordinal representingent. Arguments
number offset? - Specifies the offset at which the ordinal is taken.
Example
Print[Ord["A"]]
?? 65
Print[Ord["asdf"]]
?? 97
Print[Ord["asdf", 1]]
?? 115
Print[Ord["asdf", 1:3]]
?? [115, 100, 102]
Print[Ord[33]]
?? 33Ords[string|number ent] → [number] (string)
Vectorizes.
MapsOrd over the characters of ent if it is a string; otherwise, is equivalent to [Ord[ent]]. Example
Print[Ords["Hello!"]]
?? [72, 101, 108, 108, 111, 33]
Print[Ords[ [33, 34, 35] ]]
?? [32, 34, 35]Outers[[(*)] list, number n?] → [(*)] (list)
Vectorizes.
Returns the outermostn elements from the left and right sides of list. Arguments
number n? - Default: 1
Example
Print[Outers[1:5]]
?? [1, 5]
Print[Outers[1:5, 2]]
?? [1, 2, 4, 5]Over[ConfigureValue ...opts] → fn (functional/list)
Returns a function that will, over each element of its input list, select the first appropriate condition (if any) defined in opts and apply it to each element. Each key is a condition, and each value is a function to apply on elements satisfying that condition. Example
squareFirst := Over[0 -> Square]
Print[squareFirst[3:6]]
?? [9, 4, 5, 6]
squareOddIndices := Over[Odd -> Square]
Print[squareOddIndices[2:6]]
?? [2, 9, 4, 25, 6]
zeroOutEvenIndices := Over[Even -> 0]
Print[zeroOutEvenIndices[1:5]]
?? [0, 2, 0, 4, 0]
oddEvenPulse := Over[Odd -> Succ, Even -> Pred]
Print[oddEvenPulse[1:5]]
?? [0, 3, 2, 5, 4]
named[x] := x = 0 or x = 2
negateNamed := Over[$named -> { -_ }]
Print[negateNamed[1:5]]
?? [-1, 2, -3, 4, 5]
named[x] := x /= 0
Print[negateNamed[1:5]]
?? [-1, 2, -3, 4, 5]Overlap[[(*)] list, [(*)] search] → bool (list/logic)
Returns true if search exists as a contiguous subset in list, otherwise false. PadLeft[(*) ent, number amt, (*) fill?] → (*) (string)
Pads ent to be no less than length amt, padding with fill elements fill on the left. Arguments
string ent - appends space characters to the left of ent.
[(*)] ent - appends 0s to the left of ent.
Example
Display[PadLeft["Charles", 20]]
?? " Charles"
Print[PadLeft[1:3, 6]]
?? [0, 0, 0, 1, 2, 3]PadRight[(*) ent, number amt, (*) fill?] → (*) (string)
Pads ent to be no less than length amt, padding with fill elements fill on the right. Arguments
string ent - appends space characters to the right of ent.
[(*)] ent - appends 0s to the right of ent.
Example
Display[PadRight["Charles", 20]]
?? "Charles "
Print[PadRight[1:3, 6]]
?? [1, 2, 3, 0, 0, 0]Palindromic[[(*)]|string ent] → bool (list/logic)
Determines if ent is palindromic, that is, if it is itself reversed. parentof ((*) el) → class|nil (unary operator)
Returns the parent class of el, or nil if it doesn't exist. Periodic[fn f, x] → fn (functional)
Curries.
Returns a function which, given(*) x, applies f to x until a result occurs twice, then returns the final result. Example
dig_root := Periodic[Sum@Digits]
Print[dig_root[1853]]
?? 8PeriodicSteps[fn f, x] → fn (functional)
Curries.
Returns a function which, given(*) x, applies f to x until a result occurs twice, then returns the list of intermediate steps. Example
dig_root_steps := PeriodicSteps[Sum@Digits]
Print[dig_root_steps[1853]]
?? [1853, 17, 8, 8]PlusMinus[number a, number b] → [number] (numeric)
Vectorizes.
Returns[a - b, a + b]. Polygonal[number n, number order=3] → number (numeric/series)
Vectorizes.
Obtains thenth order-agonal number. Example
(* The triangular numbers (default) *)
Print[Polygonal[0:5, 3]]
?? [0, 1, 3, 6, 10, 15]
Print[Polygonal[0:5]]
?? [0, 1, 3, 6, 10, 15]
(* The square numbers *)
Print[Polygonal[0:5, 4]]
?? [0, 1, 4, 9, 16, 25]Pop[[(*)] list, count=nil] → (*) (list)
Pops a member from the end of list, modifying it. Returns that element. Positions[[(*)] arr, [(*)] els?] → [(*), [(*)]] (list)
Returns a list of lists of the form [id, inds], where id corresponds to a unique element of els. inds is a narray of indices where id occurs. Arguments
[(*)] els? - Default: arr.
Example
Display[Positions[ [1, 2, 3, 2, 4, 1] ]]
1 [0, 5]
2 [1, 3]
3 [2]
4 [4]
Display[Positions["Hello!", ["l", "!"]]]
"l" [2, 3]
"!" [5]Positive[number n] → bool (numeric/logic)
Vectorizes.
Returnstrue if n is greater than 0, otherwise false. Powerset[[(*)] list] → [[(*)]] (list)
Reforms result's elements.
Returns the powerset oflist. Example
Print[Powerset[ [9,4,6] ]]
?? [[], [9], [4], [9, 4], [6], [9, 6], [4, 6], [9, 4, 6]]
Print[Powerset[123]]
?? [0, 1, 2, 12, 3, 13, 23, 123]Pred[(*) ent] → (*) (data)
Returns the successor of ent. Prefixes[[(*)] list] → [[(*)]] (list)
Reforms result's elements.
Returns the non-empty prefixes oflist. Example
Print[Prefixes[1:5]]
?? [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5]]
Print[Prefixes["hi?"]]
?? ["h", "hi", "hi?"]
Print[Prefixes[901]]
?? [9, 90, 901]PreviousPrime[number n, number rep?] → number (numeric/prime)
Vectorizes.
Returns the closest previous prime beforen. Arguments
number rep? - When specified, returns the repth prime before n.
Prime[number n] → number (numeric/prime)
Vectorizes.
Returns thenth prime, starting at Prime[1] = 2. Example
Print[Prime[1:10]]PrimeDivision[number n] → [[number, number]] (numeric/prime)
Vectorizes.
Returns a list of the prime exponents ofn. That is, a list of base-exponent pairs [[p1, e1], ..., [pN, eN]] such that and . PrimeFactors[number n] → [number] (numeric/prime)
Vectorizes.
Returns a list of the prime factors ofn with duplicates. PrimeNu[number n] → number (numeric/prime)
Vectorizes.
Returns the number of unique prime factors ofn. PrimeOmega[number n] → number (numeric/prime)
Vectorizes.
Returns the number of prime factors ofn. Primes[number n] → [number] (numeric/prime)
Vectorizes.
Returns a list of the firstn primes. Print[(*) ...args, **opts] → [(*)] (IO)
Prints each argument of args, separated by spaces. Options
after → String printed after everything else. Default: "\n".
before → String printed before everything else. Default: "".
joiner → The string which joins args. Default: " ".
Prod[[number] list] → number (list)
Returns the product of all members of list. Prompt[string prompt?] → string (IO)
Prompts for a line of input. Returns string without trailing newline. Arguments
string prompt? - String to display before input text. Nothing if omitted.
Push[[(*)] list, (*) ...args] → [(*)] (list)
Pushes args to the end of list, modifying it. Returns list. Pythagorean[number n] → [number] (numeric/series)
Vectorizes.
Returns thenth enumeration of the Pythagorean triples. Example
Print => Pythagorean[0:10]
?? [3, 4, 5]
?? [8, 6, 10]
?? [5, 12, 13]
?? [15, 8, 17]
?? [12, 16, 20]
?? [7, 24, 25]
?? [24, 10, 26]
?? [21, 20, 29]
?? [16, 30, 34]
?? [9, 40, 41]
?? [35, 12, 37]Random[...args, **opts] → number (numeric/random)
Returns a pseudo-random number. By default, returns a random float between 0 (inclusive) and 1 (exclusive). Arguments
- If m is omitted, returns a random integer between 0 (inclusive) and n (exclusive).
- When provided, returns a random integer between n and m, inclusive.
Range[number|string min, number|string max?] → [number|string] (list)
Vectorizes.
Returns a range frommin to max inclusive. Arguments
number|string max? - If omitted, returns Range[0, min].
Example
Print[Range[1, 5]]
?? [1, 2, 3, 4, 5]
Print[Range["a", "d"]]
?? ["a", "b", "c", "d"]Rational[number a, number b] → rational (numeric)
Vectorizes.
Returns a fraction representinga / b. RBond[fn func, (*) rarg] → fn (functional)
Bonds larg to the right side of func. That is, Bond[func, rarg][...args] is the same as func[...args, rarg]. Re[(*) n] → number (numeric)
Vectorizes.
Returns the imaginary part ofn, or n if it doesn't exist. ReadChar[] → string (IO)
Reads a character from the input. ReadFloat[] → number (IO)
Reads a float from the input. ReadInt[] → number (IO)
Reads an integer from the input. ReadLine[] → string (IO)
Reads a line of input, to include any trailing newline. ReadLineLoop[(*) ...args, fn[string -> string] func] → [string] (IO)
Iterates func over lines of stdin received by Prompt[...args]. Returns a list of these lines modified by func. Arguments
fn[string -> string] func - A function that receives lines of input and returns a string.
ReadNumber[] → number (IO)
Reads a number from the input. Real[number n] → bool (numeric/logic)
Vectorizes.
Returnstrue if n has no imaginary part, otherwise false. Remove[[(*)] list, (*) ent] → [(*)] (list)
Reforms result.
Returnslist without any instances of ent. Example
Print[Remove[1:5, 3]]
?? [1, 2, 4, 5]
Print[Remove["Hello, World!", "l"]]
?? "Heo, Word!"
Print[Remove["Hello, World!", "ll"]]
?? "Hello, World!"RemoveAmong[[(*)] list, [(*)] ents] → [(*)] (list)
Reforms result.
Returnslist without any of the elements specified by ents. Example
Print[RemoveAmong[1:9, 4:7]]
?? [1, 2, 3, 8, 9]
Print[RemoveAmong["Hello, World!", $A:$Z]]
?? ello, orld!
Print[RemoveAmong[12930, 0'2'4'6'8]]
?? 12930RemoveFirst[[(*)] list, (*) ent] → [(*)] (list)
Reforms result.
Returnslist without the first occurrence of ent. Example
Print[RemoveFirst[[1, 2, 3, 3, 4, 4, 5], 3]]
?? [1, 2, 3, 4, 4, 5]
Print[RemoveFirst["Hello, World!", "l"]]
?? "Helo, World!"
Print[RemoveFirst["Hello, World!", "ll"]]
?? "Hello, World!"RemoveLast[[(*)] list, (*) ent] → [(*)] (list)
Reforms result.
Returnslist without the first occurrence of ent. Example
Print[RemoveLast[[1, 2, 3, 3, 4, 4, 3], 3]]
?? [1, 2, 3, 3, 4, 4]
Print[RemoveLast["Hello, World!", "l"]]
?? "Hello, Word!"
Print[RemoveLast["Hello, World!", "ll"]]
?? "Hello, World!"Repeat[number ent, amt] → [(*)] (list)
Vectorizes.
Returnsent repeated amt times. Example
Print[Repeat["Hello!", 3]]
?? ["Hello!", "Hello!", "Hello!"]
Print[Repeat[4, 0]]
?? []
Print[Repeat[9, 1:5]]
?? [[9], [9, 9], [9, 9, 9], [9, 9, 9, 9], [9, 9, 9, 9, 9]]Replace[string str, string|regex search, string replace?] → string (string)
Replaces all occurrences of search in str with replace. Arguments
- : "".
ReplaceF[string str, string|regex search, fn func] → string (string)
For each e matching search found in str, replaces it with func[e]. Example
Print[ReplaceF["Student 9234-B hsa received a 97.03% on their test.", /"\\d+", Reverse]]
?? Student 4329-B hsa received a 79.30% on their test.ReplaceMultiple[string str, ConfigureValue ...args] → string (string)
For each ConfigureValue search -> replace in args, replaces all occurrences of search in str with replace. Works iteratively, starting with the first replacement. Example
Print[ReplaceMultiple[
"Hello, World!",
ll -> "no",
oo -> "",
l -> "q"
]]
?? Hen, Worqd!Resize[[(*)] list, number size] → [(*)] (list)
Reforms result.
Resizeslist to be of length size, cyclically repeating elements if size exceeds #list. Example
Print[Resize["Hello!", 2]]
?? He
Print[Resize[[1, 2], 7]]
?? [1, 2, 1, 2, 1, 2, 1]Retrieve[string name] → (*) (scope)
Returns the value of the variable whose name is name. Example
a := 323
Print[Retrieve[$a]]
?? 323Reverse[(*) ent] → (*) (list)
Reverses the elements of ent. RLE[(*) list] → [[(*), number]] (list)
Returns an array representing the run-length encoded version of list. Example
Display[RLE["hmmmmm..."]]
"h" 1
"m" 5
"." 3RNG[number seed=Random.new_seed] → RNG (numeric/random)
Returns an RNG, seeded with seed, or a random value if unspecified. Root[number b, number n] → number (numeric)
Vectorizes.
Returns thebth root of n. Rot[string str, number amount=13] → str (string)
Vectorizes.
Translates every alphabetic character instr amount character to the right, wrapping around. Example
Print[Rot["Hello, World!"]]
?? Uryyb, Jbeyq!
Print[Rot["Hello, World!", 1]]
?? Ifmmp, Xpsme!
Print[Rot["Ifmmp, Xpsme!", -1]]
?? Hello, World!Rotate[[(*)] list, number amount=1] → [(*)] (list)
Vectorizes.
Rotateslist to the left by amount. Example
Print[Rotate[1:5, 2]]
?? [3, 4, 5, 1, 2]
Print[Rotate["Sorry!", -1]]
?? !SorryRotations[[(*)] list] → [(*)] (list)
Returns all rotations of list. Example
Display[Rotations[1:5]]
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4Round[number n, number r?] → number (numeric)
Vectorizes.
Returnsn rounded half-up to the nearest integer. Arguments
number r? - the precision to round. No precision if omitted.
Same[[(*)] ...args] → bool (list)
Returns true if every member in each argument is the same. Example
Print[Same[1:5]]
?? false
Print[Same[ [1, 1, 1, 1] ]]
?? true
Print[Same[ [1:3, 1:3, 1:3] ]]
?? trueSave[(*) ...args] → [(*)] (meta)
Updates values of global abstracts, respective to args. _1 would become args[0], and _n would become args[n-1]. Series[fn[number] f, number max, number start?, **config] → [number] (functional)
Obtains all non-negative values under max by repeating f. Options
include → determines whether or not to include max as an upperbound. Default: false
Example
Print[Series[Prime, 13]]
?? [2, 3, 5, 7, 11]
Print[Series[Prime, 13, include->true]]
?? [2, 3, 5, 7, 11, 13]SeriesIf[fn[n] f, fn[n->b] cond, number max, number start?, **config] → [number] (functional)
Obtains all non-negative values under max which satisfy cond by repeating f. Options
include → determines whether or not to include max as an upperbound. Default: false
Example
Print[SeriesIf[Prime, Odd, 13]]
?? [3, 5, 7, 11]
Print[SeriesIf[Prime, Odd, 13, include->true]]
?? [3, 5, 7, 11, 13]Shift[[(*)] list, count=nil] → (*) (list)
Pops a member from the start of list, modifying it. Returns that element. Shuffle[[(*)] list, **opts] → [(*)] (list/random)
Reforms result.
Shuffles the contents oflist. Options
RNG → specifies which RNG to shuffle by.
Sign[number n] → number (numeric)
Vectorizes.
Returns the sign ofn; Returns -1 if n is negative, 1 if it is positive, and 0 otherwise. Sin[number n] → number (numeric/trig)
Vectorizes.
Calculates .Sinh[number n] → number (numeric/trig)
Vectorizes.
Calculates .Slices[[(*)] list, number|[number] skew=(1..list.size).to_a] → [[(*)]] (list)
Returns all slices of list of length skew. Example
Print[Slices[1:6, 2]]
?? [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]SlicesFill[[(*)] list, number|[number] skew=(1..list.size).to_a, **opts] → [[(*)]] (list)
Returns all slices of list of length skew, including an implied threshold of entities to the left and right of list. Options
fill → The entity to fill the threshold. Default: 0.
compact → If true, removes the treshold after the slices are generated. Default: false.
repeat →
Example
Print[SlicesFill[1:6, 2]]
?? [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 0]]
Print[SlicesFill["a":"f", 2, fill->" "]]
[[" ", "a"], ["a", "b"], ["b", "c"], ["c", "d"], ["d", "e"], ["e", "f"], ["f", " "]]
Print[SlicesFill[1:3, 2, compact->true]]
?? [[1], [1, 2], [2, 3], [3]]
Print[SlicesFill[1:3, 2, repeat->3]]
?? [[0, 0], [0, 0], [0, 1], [1, 2], [2, 3], [3, 0], [0, 0], [0, 0]]Sparse[[(*)] list, (*) search?] → hash (list)
Converts list to a hash of sparse values. Arguments
(*) search? - if specified, treats search as the assumed value.
Example
rand := Configure[Random, RNG->RNG[104]]
vals := Do[ N@{ rand[] < 0.1 }, 100]
Print[Sparse[vals]]
?? {11=>1, 32=>1, 35=>1, 43=>1, 51=>1, 55=>1, 67=>1, 71=>1, 86=>1}Split[string str, string|regex sep?] → [string] (string)
Vectorizes.
Splitsstr on occurrences of sep. When sep is omitted, splits str on whitespace. Sqrt[number n] → number (numeric)
Vectorizes.
Returns the square root ofn. The result is imaginary if n is negative. Square[number n] → number (numeric)
Vectorizes.
Returns the square ofn. StdDev[[number] list] → number (list)
Calculates the standard deviation of list. Stdin[] → string (IO)
Reads all of STDIN. Stdout[(*) ...args] → nil (IO)
Writes args, joined together, to STDOUT. String[(*) ent, ...modes] → string (conversion)
Converts ent to a string. Subtract[number ...args] → number (numeric)
Subtracts each number in args by the next. That is, folding subtraction over args. Succ[(*) ent] → (*) (data)
Returns the successor of ent. Suffixes[[(*)] list] → [[(*)]] (list)
Reforms result's elements.
Returns the non-empty suffixes oflist. Example
Print[Suffixes[1:5]]
?? [[1, 2, 3, 4, 5], [2, 3, 4, 5], [3, 4, 5], [4, 5], [5]]
Print[Suffixes["hi?"]]
?? ["hi?", "i?", "?"]
Print[Suffixes[901]]
?? [901, 1, 1]TakeWhile[fn cond, [(*)] list] → list (functional)
Reforms result.
Returns elements fromlist until before the first element which does not satisfy cond. Example
Display[TakeWhile[{_ /= sp}, "Hello, World!"]]
?? "Hello,"
Print[TakeWhile[Even, [2, 4, 6, 1, 2, 3]]]
?? [2, 4, 6]
Print[TakeWhile[IsPrime, 357923]]
?? 357Tan[number n] → number (numeric/trig)
Vectorizes.
Calculates .Tanh[number n] → number (numeric/trig)
Vectorizes.
Calculates .Tie[(*)|fn ...args] → (*)|fn (functional)
Ties args together. Arguments
(*) args - Concatenates all args together.
fn args - Creates a tie between all of args.
Example
Print[Tie[1:3, 5:7]]
?? [1, 2, 3, 5, 6, 7]
f := Tie[Double, Halve]
Print[f[1, 2, 3, 4, 5, 6]]
?? [2, 1, 6, 2, 10, 3]TieArray[fn ...funcs] → fn (functional)
Tie, but applied to the first argument instead of all arguments. Example
f := TieArray[Double, Halve]
Print[f[1:6]]
?? [2, 1, 6, 2, 10, 3]ToBase[number num, number base] → [number] (numeric/bases)
Vectorizes.
Convertsnum to base base. Translate[string str, string source, string repl] → string (string)
Replaces each character in source with the respective character in repl in str. Character ranges are specified with -. Example
Print[Translate["Hello, World!", "a-z", "A-Z"]]
?? "HELLO, WORLD!"
Print[Translate["No one is here today, James", "a-zA-Z", "A-Za-z"]]
?? "nO ONE IS HERE TODAY, jAMES"TriangleRange[number a, number b] → [[number, number]] (list)
Returns an array of lists representing all pairs (x, y) such that a <= y <= b and a <= x < y. TriangleSelect[fn cond, number a, number b] → [[number, number]] (list)
Returns an array of lists representing all pairs (x, y) satisfying cond such that a <= y <= b and a <= x < y. Triangular[number n] → number (numeric/series)
Vectorizes.
Returns thenth Triangular number. Example
Print[Triangular[0:5]]
Print[Polygonal[0:5, 3]]
?? [0, 1, 3, 6, 10, 15]Truthy[(*) arg] → bool (logic)
Returns true if arg is truthy, false otherwise. typeof ((*) el) → Type (unary operator)
Returns the type of el. UnBin[[number] n] → number (numeric/bases)
Converts from base 2 (binary) to base 10. UnHex[[number] n] → number (numeric/bases)
Converts from base 16 (hexadecimal) to base 10. Union[[(*)] ...lists] → [(*)] (list)
Returns an array representing the union of all lists in lists. Unique[[(*)] list, number count?] → [(*)] (list)
Vectorizes. Reforms result.
Returns the non-duplicated elements inlist. Arguments
number count? - Limits the occurences of each element to count.
Example
Print[Unique[ [1, 2, 3, 2, 4, 7, 6, 7] ]]
?? [1, 2, 3, 4, 7, 6]
keep2 := Unique&2
Print[keep2[ [1, 2, 2, 3, 3, 3, 4, 9, 9, 9, 9, 5] ]]
?? [1, 2, 2, 3, 3, 4, 9, 9, 5]
Print[Unique["Hello, World!"]]
?? Helo, Wrd!
Display => Unique["There are certain people here!", 0:8]
?? ""
?? "Ther actinpol!"
?? "There ar ctainpoplh!"
?? "There are crtain poplh!"
?? "There are certain popl hr!"
?? "There are certain peopl hr!"
?? "There are certain people hr!"
?? "There are certain people her!"
?? "There are certain people here!"UniqueBy[fn map, [(*)] list, number count?] → [(*)] (list)
Curries. Reforms result.
Returns the non-duplicated elements inlist according to the image of map. Arguments
number count? - Limits the occurences of each element to count.
Example
words := ["Hello!", "world", "no!", "1234", "I swear I lived", "azure"]
Print[UniqueBy[Last, words]]
?? ["Hello!", "world", "1234", "azure"]
ClassNamed[Person]! {
name .= _1
age .= _2
$string[] .= $"${name}, age ${age}"
}
people := [
Person["John", 14],
Person["Riker", 15],
Person["Jackson", 15],
Person["Amy", 13],
Person["Marie", 14],
Person["Teressa", 16]
]
by_age := UniqueBy[.age]
Print => by_age[people]
?? John, age 14
?? Riker, age 15
?? Amy, age 13
?? Teressa, age 16UnOct[[number] n] → number (numeric/bases)
Converts from base 8 (octal) to base 10. Unshift[[(*)] list, (*) ...args] → [(*)] (list)
Pushes args to the start of list, modifying it. Returns list. UnSparse[Hash[(*) -> (*)] ent, (*) fill?] → [(*)] (list)
Treats ent as a hash where keys are indices and values are values, and converts to an array, filling in empty values with fill. Arguments
(*) fill? - default: nil.
Example
test := <~ 0 -> 3, 2 -> 4, 6 -> 3 ~>
Print[UnSparse[test]]
?? [3, 0, 4, 0, 0, 0, 3]
Print[UnSparse[test, nil]]
?? [3, nil, 4, nil, nil, nil, 3]Upcase[string str] → string (string)
Vectorizes.
Replaces all lowercase letters instr with the respective uppercase one. Example
Print[Upcase["Hello, World!"]]
?? HELLO, WORLD!
Print[Upcase[">>> NO ONE"]]
?? >>> NO ONE
Print[Upcase["le monde"]]
?? LE MONDEUpperTriangle[[[(*)]] mat, bool strict?] → [[(*)]] (list/matrix)
Returns the upper triangle of mat, where the remaining values are replaced with zeroes. Arguments
bool strict? - If true, includes the diagonal. Default: true.
Example
mat := Integers[3, 3] + 1
Display[mat]
?? 1 2 3
?? 4 5 6
?? 7 8 9
Display[UpperTriangle[mat]]
?? 1 2 3
?? 0 5 6
?? 0 0 9
Display[UpperTriangle[mat, true]]
?? 0 2 3
?? 0 0 6
?? 0 0 0V[(*) ...args] → [(*)] (data)
Returns an array of the arguments. Wait[number n=NOT_PROVIDED] → number (IO)
Sleeps for `n` seconds, or indefinitely if no argument is provided. Returns `n`. While[expression cond, expression body] → (*) (logic)
While cond evaluates as truthy, evaluates body. Returns nil if cond was false before executing body. Example
i := 0
While[i < 5, Print[i]; i := i + 1]
?? 0
?? 1
?? 2
?? 3
?? 4
While[false, Print["Hello!"]]
?? nothing is printedXnor[(*) a, (*) b] → bool (logic)
Logical biconditional. Returns true if both a and b are truthy or falsey, false otherwise. Example
Print[TruthTrablePretty["Xnor", 2]]
?? A | B | Xnor[A, B]
?? ---+---+------------
?? 0 | 0 | 1
?? 0 | 1 | 0
?? 1 | 0 | 0
?? 1 | 1 | 1Xor[(*) a, (*) b] → bool (logic)
Logical exclusive disjunction. Returns true if exactly one of a and b are truthy, false otherwise. Example
Print[TruthTrablePretty["Xor", 2]]
?? A | B | Xor[A, B]
?? ---+---+-----------
?? 0 | 0 | 0
?? 0 | 1 | 1
?? 1 | 0 | 1
?? 1 | 1 | 0((*) a) xor ((*) b) → bool (operator/logic)
Returns true if exactly one of a and b is truthy, false otherwise. Zero[number n] → bool (numeric/logic)
Vectorizes.
Returnstrue if n is 0, otherwise false.