Polynomix/Symbols

From Esolang
Jump to navigation Jump to search

Back to Polynomix

!
    Adverb: Turns an expression into an operator and an operator to a reference.
    Examples:
        10 fact!   $$ Calls fact(10)
        +!         $$ Reference for the function +
"
    Character constructor. Followed by any character make a character constant.
    Examples:
        "a   $$ The character constant 'a'
#
    1/ Assignment. Dyadic: Assigns left to right, evaluates to left. Double if it's a declaration.
    Examples:
        3##x   $$ let x = 3
        2#x    $$ x = 2
    2/ Struct declaration. Monadic: Declares a custom structure.
    Examples:
        Point#   $$ struct Point
    3/ Adverb: Transforms an operator into its corresponding compound assignment operator.
    Examples:
        a+#1   $$ a += 1
$
    1/ TypeString quotes. Makes a TypeString.
    2/ Preprocessor commands (use with \).
    Examples:
        \$1.plx+$    $$ #include <1.plx> 
        \$abjad#$    $$ #define abjad
        \$abjad#1$   $$ #define abjad 1
        \$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
        Expr -> Unknown rank lift.
            Example: (^3 + 2^ + 1) %   $$ Result: (^^3 + 2^^ + 1)
        Pair<List, List> / List<List> -> 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]
    Tryadic
        List, *, * -> Replace objects.
            Example: [1 1 4 5 1 4] %(1 2)   $$ Result: [2 2 4 5 2 4]
&
    Monadic
        Expr -> Unknown rank drop.
            Example: (^^3 + 2^^ + 1) &   $$ Result: (^3 + 2^ + 1)
    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|)
    Tryadic
        List, List, Nil/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] %(1 2)   $$ calling tryadic % with right arguments 1 and 2
        ((a b)> a + b)         $$ dyadic lambda
        ((a$+$)> a -)          $$ typed lambda
    3/ Lambdas(with typed argument) grouping.
        (((a$+$)> a-)((a$[]$)> a/))   $$ overloaded lambda list
*
    Monadic
        Expr -> Absolute value.
            Example: \3 *   $$ Result: 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]
    Tryadic
        List, List, List -> Replace substrings.
            Example: `ababaxaba' *(`aba' `123')   $$ Result: `123bax123'
+
    Monadic
        Expr -> Round down (floor)
            Example: 24/10 +   $$ Result: 2
        List -> Sort (Compare operator: <)
            Example: [1 4 2 8 5 7] +   $$ Result: [1 2 4 5 7 8]
        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]
        Expr, List[Expr] -> Coefficient extraction.
            Example: (^2 + 3^ + 2) % [2]   $$ Result: 1
        List, Expr/Nil -> 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)
,
    Dyadic
        *, * -> Make pair.
-
    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|)
    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])
        *, Type -> Built-in type Conversion.
            Example: 65 - $"$   $$ Result: "A
.
    Extensions of commands. See below.
/
    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
    Tryadic
        List, Expr/List, * -> Set Item (Replace?)
            Example: [1 2 3 4] / (3 5)   $$ Result: [1 2 3 5]
        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
    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/ Nil literal (use with \).
    Examples:
        \;   $$ Nil
<
    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
        Struct -> Value behind.
            Example:
                Point #
                2,2 .Point ## a
                a <               $$ Result: (2,2)
    Dyadic
        -> Less-than comparison.
            Example: 3 < 4   $$ Result: (1|)
=
    Monadic
        List -> Flat.
            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|)
    Tryadic
        Expr, Expr, Expr -> Range with start-end-step.
            Example: 1 =(10 2)   $$ Result: [1 3 5 7 9]
>
    Lambda generator.
    Example:
        a > a + 1         $$ monadic lambda function
        > + 1             $$ the same as above
        (a b)> a + b / 2  $$ dyadic lambda function
    * This operator has less precedence than other operators on the right!
    * This operator cannot be overloaded!
?
    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
    Monadic usage: Continue. Go to the end of the current code block and returns CONT.
    * 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 5 6][8 10 12][12 15 18]]
^
    Marks an unknown. ^ means x, ^^ means y, ^^^ means z, etc.
    Example: (^2 + 2^ + 1)
    * This operator has more precedence than other operators!
    * This operator cannot be overloaded!
`
    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]
~
    Monadic
        List<Char> -> Evaluate.
            Example: `2 + 3' ~   $$ Result: 5
    Dyadic
        List, Lambda / Code block -> For loop / Map (applies lambda to each element). CONTs are omitted from the result list.
            Example: [1 2 3 4] ~ > * 2   $$ Result: [2 4 6 8]
        Expr, Expr -> Evaluate expression.
            Example: (^2 + 3^ + 2) ~ 5   $$ Result: 42
    * This operator cannot be overloaded!

Extended commands:
!.
    Operator: Recursion. The current lambda expression as an operator.
#. (unused)
%.
    Monadic
        List<Char> -> ls. Return Pair<List<folder names>,List<file names>>.
&.
    Monadic
        -> Repr.
    Dyadic
        List, Lambda -> Filter.

*. (unused)
+. (unused)
,. (unused)
-. (unused)
/.
    Niladic
        Nil -> Unix Timestamp (in seconds).
    Monadic
        List<Char> -> Execute system command.
        Expr -> Sleep(seconds).

:. (unused)
;. (unused)
<.
    Niladic
        Nil -> Get a character from stdin.
    Monadic
        List<Char> -> Get a file's content as a string, or HTTP GET.

=. (unused)
>.
    Monadic
        -> Print.
            Example: `Hello, world!' >.   $$ Result: `Hello, world'!
    Dyadic
        *, List<Char> -> Print into file, or HTTP POST.

?. (unused)
@.
    Dyadic/Tryadic
        List, Lambda (, Beginning value) -> Prefix reduce.

^. (unused)
|. (unused)
~.
    Dyadic/Tryadic
        List, Lambda (, Beginning value) -> Reduce.