Polymorphix/Symbols
Jump to navigation
Jump to search
!
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 the operands of an operator. (APL's commute.)
Examples:
10 *!! $$ 10 * 10 = 100
2 -!! 3 $$ 3 - 2 = 1
"
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 (Use with \).
Examples:
a+\#1 $$ a += 1
$
1/ TypeString quotes. Makes a TypeString.
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?$ $$ #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> -> 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]
Triadic
List, *, * -> Replace objects.
Example: [1 1 4 5 1 4] %(1 2) $$ Result: [2 2 4 5 2 4]
Tetradic
List, *, *, Expr -> Replace objects with maxreplace.
Example: [1 1 4 5 1 4] %(1 2 2) $$ Result: [2 2 4 5 1 4]
&
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, 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 triadic % 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]
Triadic
List, List, List -> Replace substrings.
Example: `ababaxaba' *(`aba' `123') $$ Result: `123bax123'
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 (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]
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)
Lambda, Lambda -> Merge
,
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])
.
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
Triadic
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|)
Triadic
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]]
^
Monadic
List -> Enumerate.
Example: ["a "b "c] ^ $$ Result: [(1,"a)(2,"b)(3,"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
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]
~
Monadic
Expr -> Char.
Example: 65 ~ $$ Result: "A
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]
* 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.
*.
Monadic
-> Str.
+.
Dyadic
Expr, Expr -> Encode (Base number conversion).
Example: 100 +. 2 $$ [1 1 0 0 1 0 0]
List, Expr -> Decode (Base number conversion).
Example: [1 1 0 0 1 0 0] +. 2 $$ 100
List, List<Expr>/Lambda -> Partition.
Example: [3 4 5 6 7] +. [3 1 2 0 1] $$ [[6][4 7][5][3]]
,. (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. Always calls *. before printing.
Example: `Hello, world!' >. $$ Result: Hello, world!
Dyadic
*, List<Char> -> Print into file, or HTTP POST.
?. (unused)
@.
Dyadic/Triadic
List, Lambda (, Beginning value) -> Prefix reduce.
Example: [1 1 4 5 1 4] @. +! $$ Result: [1 2 6 11 12 16]
^. (unused)
|. (unused)
~.
Dyadic/Triadic
List, Lambda (, Beginning value) -> Reduce.
Example: [1 1 4 5 1 4] ~. +! $$ Result: 16