We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Polynomix/Symbols

From Esolang
Jump to navigation Jump to search

Back to Polynomix This is the reference symbol dictionary, sorted with ASCII order.

The Symbols Reference Manual of the Polynomix Language

* Expr means a number, not any expression. An Expr can be any rational, or Infinity/NaN.
* There is no operator precedence (excluding syntaxes like adverbs). Expressions evaluate strictly from left to right.

* The names after a symbol is its aliases. Write the alias (usually its <3-character prefixes also work) with empty parentheses
  so that the interpreter will treat them like the symbol. e.g. "transpose()" or "tra()" are equivalent to "%".

!
    Adverb: Turns an expression into an operator and an operator to a reference.
    Examples:
        10 fact!   $$ Calls fact(10)
        +!         $$ Reference for the function +
    !! Adverb: Swaps or duplicates the operands of an operator based on the number of !!s and arguments.
     This adverb can be chained. Let n-1 be the number of times !! is chained (i.e., 2(n-1) exclamation marks).
      Its behavior depends on the number of arguments passed to the operator:
       Single argument: Duplicates the argument, result into n copies.
       Multiple arguments: Swaps the 1st argument with the nth argument.  
    Examples:
        10 *!!    $$ 10 * 10 = 100
        2 -!! 3   $$ 3 - 2 = 1
        10f!!!!!  $$ same as 10f!(10 10) [Note:f! is an operator, so here it's 4 exclamation marks]
        10f!!!!!(20 30)  $$ same as 30f!(20 10)
"
    Character constructor. Followed by any character make a character constant.
    Examples:
        "a         $$ The character constant 'a'
        "\n        $$ newline
        "\t        $$ tab
        "\r        $$ carriage return
        "\b        $$ backspace
        "\p        $$ backtick
        "\q        $$ single quote
        "\1234;    $$ Unicode character with specified code point
#
    1/ Assignment. Dyadic: Assigns left to right, evaluates to left. Add \ on the variable if it's a declaration.
    Examples:
        3#\x   $$ declares x as 3
        2#x    $$ let x be 2
        (5,6)#(\a,b)  $$ declare a as 5 and let b be 6
    2/ Closure. Monadic: Closes the variable in current scope.
    Examples:
        1#\a          $$ declare a as 1
        {             $$ enter scope
            a#;       $$ close a
            a+1 # a   $$ a is now 2
        }             $$ exit scope, original a is restored
        a             $$ 1
    3/ Adverb: Transforms an operator into its corresponding compound assignment operator. Prefixal.
    Examples:
        a #+ 1   $$ a += 1
$
    1/ TypeString quotes. Makes a TypeString.
        $;$   $$ Null
        $=$   $$ Bool
        $"$   $$ Char
        $/$   $$ Type
        $+$   $$ Expr
        $,$   $$ Pair
        $[]$  $$ List
        $>$   $$ Func
        ${*},1$   $$ Pair<T,T> - {*} captures type, and 1 requires the exact same type
        $[],[]$   $$ Dict (i.e. Pair<List,List>)
        ${+|["]|[1.]|[1.],[1.]}$   $$ JSON (i.e. Expr/List<Char>/List<JSON>/Dict<JSON,JSON>); 1. means the element must match the exact same TypeString structure captured by group 1
    2/ Preprocessor commands (use with \).
    Examples:
        \$1.plx+$    $$ #include <1.plx>
        \$1.plx+a$   $$ include all of the things in 1.plx but add a_ prefix
        \$abjad#$    $$ #define abjad
        \$abjad#1$   $$ #define abjad 1
        \$abjad*$    $$ #undef abjad
        \$abjad?$    $$ #ifndef abjad
        \$abjad!$    $$ #ifdef abjad
        \$abjad.?$   $$ #elif !defined(abjad)
        \$abjad.!$   $$ #elif defined(abjad)
        \$.$         $$ #else
        \$@$         $$ #endif
    3/ Comment. $$ for one-liner and $$$...$ for multi-liner(can't be nested).
% 
transpose, modulo, indexes
    Monadic
        Pair<List, List> / List<List> / List<Pair> -> Transpose.
            Example: [[1 4 7][2 5 8][3 6 9]] %   $$ Result: [[1 2 3][4 5 6][7 8 9]]
    Dyadic
        Expr, Expr -> Modulus.
            Example: 8 % 3   $$ Result: 2
        List, * -> Index.
            Example: [1 1 4 5 1 4] % 1   $$ Result: [0 1 4]
&
typeof, and, gcd, intersect, rotate, split, isinstance
    Monadic
        * -> Type of.
            Example: 2 &   $$ Result: $+$
    Dyadic
        Bool, Bool -> AND.
            Example: (0|) & (1|)   $$ Result: (0|)
        Expr, Expr -> GCD.
            Example: 6 & 10   $$ Result: 2
        List, List -> Set intersection.
            Example: [2 3 4 5] & [3 5 7 9]   $$ Result: [3 5]
        List, Expr -> Rotation.
            Example: [1 2 3 4] & \1   $$ Result: [4 1 2 3]
        *, Type -> Check if is instance.
            Example: [2 3 4 5] & $[+]$   $$ Result: (1|)
    Triadic
        List, List, Null/Expr -> Split by delimiter (substring) with maxsplit.
            Example:
                `comma, delimited, text' &(`, ' \;)   $$ Result: [`comma' `delimited' `text']
                `comma, delimited, text' &(`, ' 1)   $$ Result: [`comma' `delimited, text']
            
'
    String constant terminator (closing quote).
()
    1/ Expression grouping.
    Examples:
        2 * (3 + 5)   $$ Result: 16
    2/ Multiple argument function call/function definition.
    Examples:
        [1 1 4 5 1 4] f!(1 2)   $$ calling triadic f! with right arguments 1 and 2
        (a b> a + b)         $$ dyadic lambda
        (a$+$> a -)          $$ typed lambda
*
absolute, prefixes, multiply, repeat, find, dynamic, compose, replace, iterate
    Monadic
        Expr -> Absolute value.
            Example: \3 *   $$ Result: 3
        List -> All of the prefixes.
            Example: [1 2 3] *   $$ Result: [[1] [1 2] [1 2 3]]
    Dyadic
        Expr, Expr -> Multiplication.
            Example: 3 * 8   $$ Result: 24
        List, Expr -> List repetition.
            Example: [1 2 3] * 3   $$ Result: [1 2 3 1 2 3 1 2 3]
        List, List -> Indexes of substrings.
            Example: `ababaxaba' * `aba'   $$ Result: [0 2 6]
        List, Func -> Dynamic apply.
            Example: [1 2] * +!  $$ Result: 3
        Func, Func -> Composition.
    Triadic
        List, List, List -> Replace substrings.
            Example: `ababaxaba' *(`aba' `123')   $$ Result: `123bax123'
        *, Func, List -> Iterate over a list.
            Example: 0 * (+! [1 2 3])   $$ Result: 6
    Tetradic
        List, List, List, Expr -> Replace substrings with maxreplace.
            Example: `ababaxaba' *(`aba' `123' 1)   $$ Result: `123baxaba'
+
floor, ranking, random, add, concatenate, sample, shuffle
    Monadic
        Expr -> Round down (floor)
            Example: 24/10 +   $$ Result: 2
        List -> Sort index (Compare operator: <)
            Example: [1 4 2 8 5 7 7] +   $$ Result: [0 2 1 6 3 4 4]
        Pair<Expr, Expr> -> Random integer between
            Example: 1,10 +   $$ Result: Random integer between 1(inclusive) and 10(exclusive)
    Dyadic
        Expr, Expr -> Addition
            Example: 3 + 4   $$ Result: 7
        List, List -> Concatenation.
            Example: [1 2] + [3 4]   $$ Result: [1 2 3 4]
        List, Expr/Null -> Random sample/shuffle.
            Examples:
                [1 2 3 4] + 2    $$ Result: [2 4] (random sample)
                [1 2 3 4] + \;   $$ Result: [3 1 4 2] (random shuffle)
        Func, Func -> Merge
,
    Monadic
        * -> Close in a list.
            Example: 2,   $$ Result: [2]
    Dyadic
        *, * -> Make pair.
    * This operator's monadic and dyadic usage cannot be overloaded!
-
unique, negate, not, latter, subtract, difference, chop
    Monadic
        List -> Remove duplicates.
            Example: [1 2 2 3 1 3] -   $$ Result: [1 2 3]
        Expr -> Negate.
            Example: 3 -   $$ Result: \3
        Bool -> NOT.
            Example: (1|) -   $$ Result: (0|)
        Pair -> Second.
            Example: 1,2 -   $$ Result: 2
    Dyadic
        Expr, Expr -> Subtraction.
            Example: 8 - 3   $$ Result: 5
        List, List -> Set difference.
            Example: [1 2 3 4] - [2 4 6]   $$ Result: [1 3]
        List, Expr -> Split into heads and tails.
            Example: [1 2 3 4 5] - 2   $$ Result: ([1 2],[3 4 5])
.
    1/ Extensions of commands. See below.
    2/ Struct definition.
    Example: 2,2 Point.  $$ Result: a Point instance with internal value 2,2
    3/ Scientific notation (10^x literal).
    Example: 3 * 5.      $$ Result: 300000
/
reciprocal, reverse, swap, divide, nth, amend, change
    Monadic
        Expr -> Reciprocal.
            Example: 4 /   $$ Result: 1/4
        List -> Reverse.
            Example: [1 2 3 4] /   $$ Result: [4 3 2 1]
        Pair -> Swap.
            Example: 1,2 /   $$ Result: (2,1)
    Dyadic
        Expr, Expr -> Division.
            Example: 15 / 3   $$ Result: 5
        List, Expr/List/Pair<Expr, Expr> -> Get Item.
            Examples:
                [1 2 3 4] / 3         $$ Result: 4
                [1 3 5 7 9] / (2,4)   $$ Result: [5 7]
                [[3 4][6 8]] / [0 1]  $$ Result: 4
    Triadic
        List, Expr/List, * -> Set Item (Replace?)
            Example: [1 2 3 4] / (3 5)   $$ Result: [1 2 3 5]
        List, Func, Expr/List -> Apply on Item
            Example: [1 2 3 4] / ((+2) 3)   $$ Result: [1 2 3 6]
        List, Pair<Expr, Expr>, List -> Splice
            Example: [1 3 5 7 9] / (2,4 [2 4 6])   $$ Result: [1 3 2 4 6 9]
:
    1/ Try-except block.
    Examples:
        3*a : 1       $$ Tries evaluating 3*a, if error occurs, return 1 instead
        3*a :{___ >.}  $$ Tries evaluating 3*a, if error occurs, prints the error message (referenced with name ___)
    2/ Throw.
    Examples:
        `WhatTheFxxk' :   $$ Always raises WhatTheFxxk.
    * This operator cannot be overloaded!
;
    1/ Command separator. Used after monadic operations.
    Examples:
        [1- 3]   $$ Result: [\2] since it's dyadic -
        [1-;3]   $$ Result: [\1 3] since it's monadic -
    2/ Null literal (use with \).
    Examples:
        \;   $$ Null
<
length, former, numerator, b2int, ascii, reveal, lessthan
    Monadic
        List -> Length.
            Example: [2 3 4 5] <   $$ Result: 4
        Pair -> First.
            Example: (3,4) <   $$ Result: 3
        Expr -> Numerator.
            Example: 2/3 <   $$ Result: 2
        Char -> ASCII.
            Example: "A <   $$ Result: 65
        Bool -> to Expr.
            Example: (0|) <  $$ Result: 0
        Struct -> Value behind.
            Example:
                2,2 Point. # \a
                a <               $$ Result: (2,2)
    Dyadic
        -> Less-than comparison.
            Example: 3 < 4   $$ Result: (1|)
=
flat, range, equal
    Monadic
        List -> Flat (Reduces one level nesting).
            Example: [[1 2][[3] 4] 5 6] =   $$ Result: [1 2 [3] 4 5 6]
        Expr -> Range.
            Example: 5 =   $$ Result: [0 1 2 3 4]
    Dyadic
        -> Equality.
            Example: 3 = 3   $$ Result: (1|)
    Triadic
        Expr, Expr, Expr -> Range with start-end-step.
            Example: 2 =(1 10)   $$ Result: [1 3 5 7 9]
>
    Function. Constructs a lambda function with arguments on the left and code on the right.
    Example:
        (a > a + 1)         $$ monadic lambda function
        (a b > a + b / 2)   $$ dyadic lambda function
        (a>
            a+1#\t
            t*t
        )  $$ Multiple expressions, evaluates to the last one.
    
?
    If expression.
    Example:
        a ? 2       $$ if a is true, return 2, else CONT
        a ?(2 3)    $$ if a is true, return 2, else 3
        a ?(2 b 3)  $$ if a, 2, elif b, 3, else CONT
    * This operator cannot be overloaded!

@
    While loop. CONTs are omitted from the result list.
    Example:
        a = 0 - @ {a - 1 # a >. "\n>.}   $$ while a is not 0, decrease and print a
    A C-style for loop is also supported, with the initialize/condition/increment after the block.
    Example:
        a @(1#\i i<10 i#+1)
    Additional monadic usage: Return. Exits current function and returns the value.
    * This operator cannot be overloaded!
[]
    List constructor.
\
    Adjective:
        Expr -> Negate.
            Example: \3   $$ Literal negative 3
        Type -> Preprocessor keyword (see $).
        List / Pair -> Iterator, Operator -> Map. Can be followed by exclamation marks to adjust the way to broadcast.
            Examples:
                [2 3 4 5] \+ 7       $$ Result: [9 10 11 12]
                [2 3 4] \+ \[1 2 3]  $$ Result: [3 5 7]
                2 * \[2 3 4]         $$ Result: [4 6 8]
                [1 2 3] \!* \[4 5 6]    $$ Result: [[4 8 12] [5 10 15][6 12 18]]
^
nrange, enumerate, xor, power, reshape, reiterate
    Monadic
        Expr -> Range from 1 to n.
            Example: 5 ^   $$ Result: [1 2 3 4 5]
        List -> Enumerate.
            Example: ["a "b "c] ^   $$ Result: [(0,"a)(1,"b)(2,"c)]
    Dyadic
        Bool, Bool -> XOR.
            Example: (1|) ^ (0|)   $$ Result: (1|)
        List, List -> Setwise XOR.
            Example: [1 2 3] ^ [2 3 4]   $$ Result: [1 4]
        List, Expr -> Reshape.
            Example: [2 3 4] ^ 5   $$ Result: [2 3 4 2 3]
    Triadic
        *, Func, Expr -> Apply for n times.
            Example: 1 ^((+2) 3)   $$ Result: 7
        List, Expr, * -> Reshape with default value.
            Example: [2 3 4] ^ (5 0)   $$ Result: [2 3 4 0 0]
`
    String constant initiator (opening quote).
{}
    1/ Code block. Evaluates to the last expression in the block.
    2/ APL's Train. Expected a sequence of two or more verbs inside it, and the whole {} block is a verb.
        Each inner verb may optionally take its own right arguments.
        any train applies the second verb to the results of all the others,
        with the first verb's result used as the left argument (if dyadic) and the rest as right arguments.
        Example: [3 1 4 1 5 9 2 6 5]{~.+!/<}  $$ Result: 4  (sum(~. with right argument +!) divided(/) by length(<), i.e. average)
|
bool, or, lcm, union, regroup, slide
    Monadic
        -> Convert to Boolean.
            Example: 0 |   $$ Result: (0|)
            Example: 5 |   $$ Result: (1|)
    Dyadic
        Bool, Bool -> OR.
            Example: (0|) | (1|)   $$ Result: (1|)
        Expr, Expr -> LCM.
            Example: 6 | 10   $$ Result: 30
        List, List -> Union.
            Example: [1 2 3] | [3 4 5]   $$ Result: [1 2 3 4 5]
        List, Expr -> Regroup.
            Example: [1 2 3 4 5 6 7] | 3    $$ Result: [[1 2 3][4 5 6][7]]
    Triadic
        List, Expr, Func -> Sliding window.
            Example: [1 2 3 4 5 6 7] |(2 +!)  $$ Result: [3 5 7 9 11 13]
~
char, p2list, evaluate, inside, fixedpoint, periodic
    Monadic
        Expr -> Char.
            Example: 65 ~   $$ Result: "A
        Pair -> to List.
            Example: 2,3 ~  $$ Result: [2 3]
        List<Char> -> Evaluate.
            Example: `2 + 3' ~   $$ Result: 5
    Dyadic
        *, List -> Check if inside.
            Example: "a ~ `abjad'  $$ (1|)
        Expr, Pair<Expr,Expr> -> Check if in range.
            Example: 2 ~ (1,3)     $$ (1|)
        *, Func -> Apply until fixed-point.
            Example: 100 ~ (/2+)   $$ 100->50->25->12->6->3->1->0, result: 0
    Triadic
        *, Func, Expr -> Apply until fixed-point with time limit. Returns (reached, val).
            Example: 100 ~ ((/2+) 3)   $$ 100->50->25->12 TLE, result: ((0|),12)
        *, Func, Null -> Apply until periodic. Returns the cycle (loop section).
            Example: 54 ~ ((x > x%2=0?(x/2 x*3+1)) \;)   $$ Collatz conjecture, result: [1 4 2]
        *, Expr, Func -> Apply until period with time limit. Returns ((0|),val) or ((1|),cycle).

Extended commands:
\.
    Operator: Recursion. The current lambda expression as an operator.
#. (unused)
%.
listdir, takewhile, window
    Monadic
        List<Char> -> ls. Return Pair<List<folder names>,List<file names>>.
    Dyadic
        List, Func -> Take elements while predicate is true.
            Example: [0 0 0 1 0 2 4] %. (=0)   $$ Result: [0 0 0]
        List, Expr -> Sliding windows.
            Example: [1 2 3 4 5] %. 3   $$ Result: [[1 2 3][2 3 4][3 4 5]]
&.
represent, filter
    Monadic
        -> Repr.
    Dyadic
        List, List/Func -> Filter.

*.
string, partition
    Monadic
        -> Str.
    Dyadic
        List, List -> Partition.
            Example: [3 4 5 6 7] *. [2 2 1]   $$ Result: [[3 4][5 6][7]]
+.
sign, runlength, encode, decode, group
    Monadic
        Expr -> Sign. Return value could be \1, 0, 1, or 0/0.
            Example: \114514 +.  $$ Result: \1
        List -> Run-length encode. Returns (values, lengths).
            Example: [1 1 0 0 1 2 2 2] +.   $$ Result: [1 0 1 2],[2 2 1 3]
        Pair<List,List> -> Run-length decode.
            Example: [1 0 1 2],[2 2 1 3] +.   $$ Result: [1 1 0 0 1 2 2 2]
    Dyadic
        Expr, Expr -> Encode (Base number conversion).
            Example: 100 +. 2   $$ [1 1 0 0 1 0 0]
        List, Expr/List<Char>[name] -> Decode (Base number conversion / String encode/decode).
            Example: [1 1 0 0 1 0 0] +. 2   $$ 100
        List, List<Expr>/Func -> Group.
            Example: [3 4 5 6 7] +. [3 1 2 0 1]   $$ Result: [[6][4 7][5][3]]
,.
permutations, sort
    Monadic
        List -> Permutations.
            Example: [1 2 3] ,.   $$ [[1 2 3][1 3 2][2 1 3][2 3 1][3 1 2][3 2 1]] 
    Dyadic
        List, Func -> Sort. Func is the comparator.
            Example: [1 4 2 8 5 7] ,.<!   $$ [1 2 4 5 7 8]
-.
delete, minimum
    Monadic
        List<Char>/Pair<List<Char>[Site],List<Char>[Head]> -> Delete a file, or HTTP DELETE.
    Dyadic
        -> Minimum.
            Example: 2 -. 3  $$ Result: 2
/.
timestamp, system, sleep
    Niladic
        Null -> Unix Timestamp (in seconds).
    Monadic
        List<Char> -> Execute system command.
        Expr -> Sleep(seconds).
:. (unused)
;.
tack
    -> Always returns the first argument.

<.
input
    Niladic
        Null -> Get a character from stdin.
    Monadic
        List<Char>/Pair<List<Char>[Site],List[Head]> -> Get a file's content (always binary mode), or HTTP GET.
=. 
json
    Monadic
        List<Char> -> JSON decoding.
    Dyadic
        *, Null -> JSON generating.
>.
output
    Monadic
        -> Print. Always calls monadic *. before printing.
            Example: `Hello, world!' >.   $$ Result: Hello, world!
    Dyadic
        *[Body], List<Char>/Pair<List<Char>[Site],List[Head]> -> Print into file, create folder, or HTTP POST.

?. (unused)
@.
prefix, scan
    Monadic
        List<Expr> -> Prefix sum.
            Example: [1 1 4 5 1 4] @.    $$ Result: [1 2 6 11 12 16]
    Dyadic/Triadic
        List, Func (, Beginning value) -> Scan.
            Example: [1 1 4 5 1 4] @. +!   $$ Result: [1 2 6 11 12 16]
^.
decimal, max, c2int
    Monadic
        List<Expr> -> Decode in base 10.
            Example: [1 2 3 4 5] ^.  $$ Result: 12345
        Expr -> Encode in base 10.
            Example: 12345 ^.  $$ [1 2 3 4 5]
        Char -> Convert to number. 0~9, A~Z/a~z -> 1~26, otherwise NaN.
    Dyadic
        -> Maximum.
            Example: 2 ^. 3  $$ Result: 3
|.
sum, any, dropwhile, intersperse
    Monadic
        List<Expr> -> Sum.
            Example: [1 1 4 5 1 4] |.   $$ Result: 16
        List<Bool> -> Any.
            Example: [1 0 0 0 0] \| |.  $$ Result: (1|)
    Dyadic
        List, Func -> Drop elements while predicate is true.
            Example: [0 0 0 1 0 2 4] |. (=0)   $$ Result: [1 0 2 4]
        *, List -> Join (Insert between each item).
            Example: `,' |. [`foo' `bar' `baz'] =    $$ Result: `foo,bar,baz'
~.
factorize, product, all, reduce
    Monadic
        Expr -> Factorization.
            Example: 114514 ~.   $$ Result: [2 31 1847],[1 1 1]
        List<Expr> -> Product.
            Example: [1 2 3 4 5 6 7 8 9] ~.   $$ Result: 362880
        List<Bool> -> All.
            Example: [1 1 1 1 0] \| ~.  $$ Result: (0|)
    Dyadic/Triadic
        List, Func (, Beginning value) -> Reduce.
            Example: [1 1 4 5 1 4] ~. +!   $$ Result: 16