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.

!
    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 n times to feed the operator.
       Multiple arguments: Swaps the 1st argument with the n-th argument.  
    Examples:
        10 *!!    $$ 10 * 10 = 100
        2 -!! 3   $$ 3 - 2 = 1
        10f!!!!!  $$ same as 10f!(10 10)
        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).
%
    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]
&
    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
*
    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'
+
    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!
-
    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
/
    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. Only 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
<
    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|)
=
    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]
>
    Lambda generator.
    Example:
        a > a + 1         $$ monadic lambda function
        a b > a + b / 2   $$ dyadic lambda function
    * This is not an operator and it has less precedence than other operators on the right!
?
    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
    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 / Command -> Iterator. Can be followed by exclamation marks to lift rank.
            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]]
^
    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.
    2/ "Trains".
|
    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]
~
    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
        *, 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)
%.
    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]]
&.
    Monadic
        -> Repr.
    Dyadic
        List, List/Func -> Filter.

*.
    Monadic
        -> Str.
    Dyadic
        List, List -> Partition.
            Example: [3 4 5 6 7] *. [2 2 1]   $$ Result: [[3 4][5 6][7]]
+.
    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]]
,. (unused)
-.
    Monadic
        List<Char>/Pair<List<Char>[Site],List<Char>[Head]> -> Delete a file, or HTTP DELETE.
    Dyadic
        -> Minimum.
            Example: 2 -. 3  $$ Result: 2
/.
    Niladic
        Null -> Unix Timestamp (in seconds).
    Monadic
        List<Char> -> Execute system command.
        Expr -> Sleep(seconds).

:. (unused)
;.
    -> Always returns the first argument.

<.
    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.
=. 
    Monadic
        List<Char> -> JSON decoding.
    Dyadic
        *, Null -> JSON generating.
>.
    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)
@.
    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]
^.
    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
|.
    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'
~.
    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