Menu

Basic operators

aditsu John Barrett

Basic operators

! (exclamation)

Boolean NOT

Arity: 1 • Notation: postfix • Syntax: arg1 !
Returns 1 if the argument is "false" (0 or empty) or 0 if not.

arg1 Result Example Result
numeric or char 1 if arg1 == 0 0! 1
0 if arg1 != 0 13.25! 0
array or string 1 if arg1 is empty []! 1
0 if arg1 is not empty "foo"! 0
block not supported

# (number sign)

1. Power

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 #
Raises a number to the power of another number.

arg1 arg2 Result Example Result
numeric numeric arg1arg2 2 4# 16
10-2# 0.01
6.25 0.5# 2.5

2. Find index

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 #
Finds the first index of a value in an array, or -1 if not found.
If both arguments are arrays, it searches for a subarray (slice) rather than an element.
If one argument is a block, it is used as a condition to determine if an element is a match.

arg1 arg2 Result Example Result
array or string numeric or char index of arg2 in arg1 [1 3 5]5# 2
[1 3 5]2# -1
numeric or char array or string index of arg1 in arg2 'o"foo"# 1
array or string array or string index of arg2 as subarray of arg1 "abcde""cd"# 2
[1 3 5][1 5]# -1
["ab""cd"]["ab"]# 0
array or string block first index of arg1 for which arg2 is true [1 7 5]{4>}# 1
block array or string first index of arg2 for which arg1 is true {'A<}"foo"# -1

$ (dollar)

1. Copy from stack

Arity: 1 • Notation: postfix • Syntax: arg1 $
Copies a value from the stack, from the given position. 0 is the current top of the stack, 1 is 2nd from the top, -1 is the bottom, -2 is 2nd from the bottom etc.

arg1 Result Example Result
numeric Value from stack at arg1 position (converted to int) 3 5 1$ 3 5 3

2. Simple sort

Arity: 1 • Notation: postfix • Syntax: arg1 $
Sorts an array or string in ascending order. The array items must be of compatible types.

arg1 Result Example Result
array or string sorted array / string "hello"$ "ehllo"
[3 1.5 2]$ [1.5 2 3]

3. Sort by key expression

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 $
Sorts an array or string using a block to calculate a key for each item. The items are sorted in the order that puts their keys in ascending order. If two items have equal keys, they are kept in their initial order (the sorting algorithm is stable).

arg1 arg2 Result Example Result
array or string block sorted array / string (by key) [1 4 3 5 2]{W*}$ [5 4 3 2 1]
[2 -3 4 -5]{0>}$ [-3 -5 2 4]

% (percent)

1. Modulo (remainder)

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 %
Calculates the remainder after dividing two numbers with an integer quotient.

arg1 arg2 Result Example Result
numeric numeric remainder of arg1 / arg2 8 3% 2
8 -2.5% 0.5
-8.5 3% -2.5

2. Split without empty parts

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 %
Splits an array or string around occurrences of a separator, discarding empty pieces. Also see "/" which keeps all the pieces.

arg1 arg2 Result Example Result
array or string array or string or char arg1 split around arg2 "foobar"'o% ["f" "bar"]
[1 2 3 1 2 4][1 2]% [[3] [4]]

3. Select every nth item

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 %
Selects items from an array or string whose indices are multiples of a given number (converted to integer). The array is reversed if the number is negative.

arg1 arg2 Result Example Result
array or string numeric arg1 items with indices multiple of arg2 "foobar"2% "foa"
"foobar"-2% "rbo"
numeric array or string arg2 items with indices multiple of arg1 W[1 2 3]% [3 2 1]

4. Map (apply to all)

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 %
Transforms each item of an array or string, by running a block on it. Returns an array with the results. If a number n is given instead of an array, it converts it to a range from 0 to n-1 then applies the block.

arg1 arg2 Result Example Result
array or string block map arg2 onto each item of arg1 "Abc"{)}% "Bcd"
numeric block map arg2 onto numbers 0…arg1-1 3{_}% [0 0 1 1 2 2]
block array or string map arg1 onto each item of arg2 {'x}"abc"% "axbxcx"
block numeric map arg1 onto numbers 0…arg2-1 {_*}5% [0 1 4 9 16]

& (ampersand)

1. Bitwise AND

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 &
Performs a bit-by-bit AND on two integers or an integer and a character (through its numeric code).

arg1 arg2 Result Example Result
integer integer arg1 (bitwise) & arg2 7 11& 3
12 34& 0
integer char (char) (arg1 & arg2) 95'a& 'A
char integer (char) (arg1 & arg2) 'R67& 'B

2. Set intersection

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 &
Finds the unique common items that belong to 2 given arrays/strings, or an array and a number or character (seen as a 1-element array). The order of first occurrences in the first array/string is preserved.

arg1 arg2 Result Example Result
array or string array or string Intersection of arg1 and arg2 "hello""world"& "lo"
array or string numeric or char Intersection of arg1 and arg2 "hello"'x& ""
numeric or char array or string Intersection of arg1 and arg2 3[2 3 3 4]& [3]

3. If-then

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 &
Executes a block if a given value is true (non-zero/non-empty).

arg1 arg2 Result Example Result
non-block block Execute arg2 if arg1 is true 5[0]{"yes"}& 5 "yes"
5 0{"yes"}& 5
5"yes"{)}& 6

( (left parenthesis)

1. Decrement

Arity: 1 • Notation: postfix • Syntax: arg1 (
Decrements a number or character.

arg1 Result Example Result
numeric or char arg1 - 1 5.3( 4.3
'c( 'b

2. Uncons from left (take out first item)

Arity: 1 • Notation: postfix • Syntax: arg1 (
Removes the first item of an array or string and pushes it afterwards. It is, in a way, the opposite of Lisp's cons function, hence "uncons".

arg1 Result Example Result
array or string arg1[1…] arg1[0] "hello"( "ello"'h
[2 3]( [3]2

) (right parenthesis)

1. Increment

Arity: 1 • Notation: postfix • Syntax: arg1 )
Increments a number or character.

arg1 Result Example Result
numeric or char arg1 + 1 5) 6
'c) 'd

2. Uncons from right (take out last item)

Arity: 1 • Notation: postfix • Syntax: arg1 )
Removes the last item of an array or string and pushes it afterwards.

arg1 Result Example Result
array or string arg1[…last-1] arg1[last] "hello") "hell"'o
[2]) []2

* (asterisk)

1. Multiply

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 *
Multiplies two numbers.

arg1 arg2 Result Example Result
numeric numeric arg1 * arg2 1.24 5* 6.2

2. Repeat array

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 *
Repeats an array/string or character a given number of times. The number is expected to be non-negative, and is converted to integer (this behavior might change in the future).

arg1 arg2 Result Example Result
array or string or char numeric arg1 repeated arg2 times "hi"2.5* "hihi"
[2]3* [2 2 2]
numeric array or string or char arg2 repeated arg1 times 4'A* "AAAA"
2["hi"]* ["hi""hi"]

3. Repeat block (execute n times)

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 *
Executes a block a given number of times. The number is converted to integer, and negative numbers are treated the same as 0.

arg1 arg2 Result Example Result
block numeric execute arg1, arg2 times 5{)}3* 8
numeric block execute arg2, arg1 times 2{"hi"}* "hi""hi"

4. Join

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 *
Joins the items of an array/string using a given separator. Effectively, each item and the separator are converted to arrays/strings (if they are not already), the separator is inserted between every pair of adjacent items, and then all the arrays are concatenated.

arg1 arg2 Result Example Result
array or string array or string or char arg1 joined with separator arg2 [1 2 3]',* [1',2',3]
"foo"S* "f o o"
["ab"'c"d"]"->"* "ab->c->d"
char array or string arg2 joined with separator arg1 ' [1 2 3]* [1' 2' 3]

5. Fold (reduce)

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 *
Given an array/string and a block, it pushes the first item of the array, then successively pushes the rest of the items one by one and executes the block after each one. The array must not be empty.

arg1 arg2 Result Example Result
array or string block arg1 folded using arg2 [1 2 3 4]{+}* 10
block array or string arg2 folded using arg1 {e<}"hello"* 'e

+ (plus)

1. Add

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 +
Adds two numbers or a number and a character (through its numeric code).

arg1 arg2 Result Example Result
numeric numeric arg1 + arg2 5 3+ 8
char numeric (char) (arg1 + arg2) 'A5+ 'F
numeric char (char) (arg1 + arg2) 32'B+ 'b

2. Concatenate

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 +
Concatenates an array/string with anything else, or 2 characters into a string. Note: strings are arrays of characters, and there is no type conversion when concatenating.

arg1 arg2 Result Example Result
array or string anything arg1 concatenated with arg2 "hi"5+ ['h'i5]
[1 2][1 3]+ [1 2 1 3]
"ab"["cd"]+ ['a'b"cd"]
["ab"]["cd"]+ ["ab""cd"]
anything array or string arg1 concatenated with arg2 5[2 2]+ [5 2 2]
'j"am"+ "jam"
char char arg1 concatenated with arg2 'a'b+ "ab"

, (comma)

1. Range

Arity: 1 • Notation: postfix • Syntax: arg1 ,
Given a number or character, creates an array with all the numbers or characters smaller than the argument, starting from 0.

arg1 Result Example Result
numeric [0 1 2 … (int)arg1-1] 4, [0 1 2 3]
char [(char)0 (char)1 … arg1-1] 'f,'c,- "cde"

2. Length

Arity: 1 • Notation: postfix • Syntax: arg1 ,
Gets the length of an array or string.

arg1 Result Example Result
array or string length of arg1 "hello", 5
10,, 10

3. Filter

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 ,
Evaluates a block for each item of an array or string, and selects the items for which the result was true (non-zero/non-empty). If a number n is given instead of an array, it converts it to a range from 0 to n-1.

arg1 arg2 Result Example Result
array or string block [x in arg1 for which arg2 is true] [2 -3 1]{0>}, [2 1]
numeric block [x from 0 to (int)arg1-1 for which arg2 is true] 10{3%}, [1 2 4 5 7 8]

- (minus)

1. Subtract

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 -
Subtracts two numbers or characters (using the numeric code). Note: if "-" is followed by a digit, it is interpreted as a negative sign for the following number. Use "m" instead of "-" in that case.

arg1 arg2 Result Example Result
numeric numeric arg1 - arg2 5 3- 2
char char arg1 - arg2 'D'A- 3
char numeric (char) (arg1 - arg2) 'D3- 'A

2. Remove

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 -
Removes all occurences of a given item or array of items from an array/string. Same observation applies when the next character is a digit.

arg1 arg2 Result Example Result
array or string numeric or char arg1 without occurrences of arg2 [1 2 3 2 1]2- [1 3 1]
array or string array or string arg1 without any arg2 items "hello""hl"- "eo"
numeric or char array or string [] if arg1 in arg2, else [arg1] 2[1 3]- [2]

. (dot)

Vectorize

Arity: 3 • Notation: infix • Syntax: arg1 arg2 .op
Takes a binary operator or block literal and applies it to 2 arrays/strings, item by item, returning an array with the results. If one of the array is longer, its "extra" items are copied without modification. Effectively, .op becomes a new binary operator and can be further composed using infix operators.

arg1 arg2 op Result Example Result
array or string array or string binary operator or block literal array of (arg1[i] arg2[i] op) results [1 2][5 7 3].+ [6 9 3]
"hi"[1 2].{)*} ["hh" "iii"]

Note: when appearing next to a digit, the dot is a decimal point.

/ (slash)

1. Divide

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 /
Divides two numbers. If they are both integers, it performs an integer division.

arg1 arg2 Result Example Result
numeric numeric arg1 / arg2 5 3/ 1
9 1.2/ 7.5

2. Split by separator

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 /
Splits an array or string around occurrences of a separator. Note: "%" splits and discards the empty pieces.

arg1 arg2 Result Example Result
array or string array or string or char arg1 split around arg2 "foobar"'o/ ["f" "" "bar"]
[1 2 3 1 2 4][1 2]/ [[] [3] [4]]

3. Split by length

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 /
Splits an array or string into pieces of a given (positive) size. The last piece may be shorter if the array doesn't split evenly.

arg1 arg2 Result Example Result
array or string numeric arg1 split into pieces of length arg2 "hello"2/ ["he" "ll" "o"]
numeric array or string arg2 split into pieces of length arg1 3 5,/ [[0 1 2] [3 4]]

4. Foreach

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 /
Executes a block for each item of an array or string. If the block pushes any values, they are left on the stack ("%" is similar but collects the results in an array). If a number n is given instead of an array, it converts it to a range from 0 to n-1 then applies the block.

arg1 arg2 Result Example Result
array or string block run arg2 for each item of arg1 "Abc"{)}/ 'B'c'd
numeric block run arg2 for numbers 0…arg1-1 3{_}/ 0 0 1 1 2 2
block array or string run arg1 for each item of arg2 {1}"abc"/ 'a 1 'b 1 'c 1
block numeric run arg1 for numbers 0…arg2-1 {_*}5/ 0 1 4 9 16

: (colon)

1. Set variable

Arity: 2 • Notation: infix • Syntax: arg1 :var
Stores a value into a variable, and also leaves it on the stack.

arg1 var Result Example Result
anything variable name arg1 stored in var 2:XX 2 2

2. Quick map (apply to all)

Arity: 2 • Notation: infix • Syntax: arg1 :op
Takes a unary operator and applies it on all the items of an array or string. Equivalent to {op}%. Effectively, :op becomes a new unary operator and can be further composed using infix operators.

arg1 op Result Example Result
array or string unary operator map op onto each item of arg1 "Abc":) "Bcd"
[1 2]:_ [1 1 2 2]

3. Quick fold (reduce)

Arity: 2 • Notation: infix • Syntax: arg1 :op
Takes a binary operator and folds an array or string using it. Equivalent to {op}*. Effectively, :op becomes a new unary operator and can be further composed using infix operators.

arg1 op Result Example Result
array or string binary operator arg1 folded using op [1 2 3 4]:+ 10

; (semicolon)

Pop and discard

Arity: 1 • Notation: postfix • Syntax: arg1 ;
Pops the top value from the stack and discards it.

arg1 Result Example Result
anything none, just pops arg1 2 3; 2

< (less than)

1. Compare (less)

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 <
Compares two compatible values and returns 1 if the first one is less than the second one, else 0. Arrays/strings are compared lexicographically.

arg1 arg2 Result Example Result
numeric or char numeric or char 1 if arg1 < arg2 (by numeric value), else 0 2 3< 1
'A65< 0
array or string array or string 1 if arg1 < arg2 (lexicographically), else 0 "abc""ad"< 1
[[65][67]]["AB"]< 1

2. Slice before

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 <
Given an array/string and a number k, selects the first k items from the array (i.e. the items with index less than k). If n is the length of the array, and k is not within the 0…n range, then k is adjusted as follows:
- if k>n, k is replaced with n
- if k is within -n…-1, k is replaced with k+n
- if k<-n, k is replaced with 0

arg1 arg2 Result Example Result
array or string numeric arg1[0…arg2-1] "test123"5< "test1"
[1 3]5< [1 3]
numeric array or string arg2[0…arg1-1] -3"test123"< test
-4[1 2 3]< []

= (equals)

1. Compare (equal)

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 =
Compares two compatible values and returns 1 if they are equal, else 0.

arg1 arg2 Result Example Result
numeric or char numeric or char 1 if arg1 == arg2 (by numeric value), else 0 2 3= 0
'A65= 1
array or string array or string 1 if arg1 == arg2 (item by item), else 0 "abc""ad"= 0
3,[0 1 2]= 1

2. Get array item

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 =
Given an array/string and a number k, gets the item with index k (0-based) from the array. If n is the length of the array, and k is not within the 0…n-1 range, then k is replaced with k mod n (within 0…n-1). In other words, the array wraps around indefinitely in this context.

arg1 arg2 Result Example Result
array or string integer arg1[arg2] "test"2= 's
[1 3]5= 3
integer array or string arg2[arg1] -3"test123"= '1
0[1 2 3]= 1

3. Find value

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 =
Finds the first item of an array or string that satisfies a given condition. If not found, it doesn't push anything.

arg1 arg2 Result Example Result
array or string block first item of arg1 for which arg2 is true "test"{'f<}= 'e
[1 2]{3>}=
block array or string first item of arg2 for which arg1 is true {3%}[3 4 5]= '4

> (greater than)

1. Compare (greater)

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 >
Compares two compatible values and returns 1 if the first one is greater than the second one, else 0. Arrays/strings are compared lexicographically.

arg1 arg2 Result Example Result
numeric or char numeric or char 1 if arg1 > arg2 (by numeric value), else 0 3 2> 1
'A65> 0
array or string array or string 1 if arg1 > arg2 (lexicographically), else 0 "ad""abc"> 1
[[65][67]]["AB"]> 0

2. Slice from

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 >
Given an array/string and a number k, selects everything but the first k items from the array (i.e. the items with index k or greater). If n is the length of the array, and k is not within the 0…n range, then k is adjusted as follows:
- if k>n, k is replaced with n
- if k is within -n…-1, k is replaced with k+n
- if k<-n, k is replaced with 0

arg1 arg2 Result Example Result
array or string numeric arg1[arg2…] "test123"5> "23"
[1 3]5> []
numeric array or string arg2[arg1…] -3"test123"> "123"
-4[1 2 3]> [1 2 3]

? (question mark)

If-then-else

Arity: 3 • Notation: postfix • Syntax: arg1 arg2 arg3 ?
Pushes one of two values depending on whether a condition is true or false (false meaning number/char 0 or empty string/array). If the value is a block, it is executed.

arg1 arg2 arg3 Result Example Result
non-block anything anything arg2 if arg1 is true, else arg3 1 2 3? 2
[]"yes"{'n_)+}? "no"

@ (at sign)

Rotate 3

Arity: 3 • Notation: postfix • Syntax: arg1 arg2 arg3 @
Brings the third value (counted from the top of stack) up to the top of the stack, pushing down the first two.

arg1 arg2 arg3 Result Example Result
anything anything anything arg2 arg3 arg1 12"foo"{)}@ "foo"{)}12

[ (left square bracket)

Start array

Arity: 0 • Syntax: [
This doesn't modify the stack, but marks the current position so that any values pushed afterwards can be wrapped into an array. If any values are popped, the mark is automatically moved back.

\ (backslash)

Swap

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 \
Swaps the top 2 values on the stack.

arg1 arg2 Result Example Result
anything anything arg2 arg1 5"hi"\ "hi"5

] (right square bracket)

End array

Arity: n/a • Syntax: ]
Pops all the values pushed on the stack after the last unclosed "[", puts them in an array and pushes that array. If there is no unclosed "[", then it takes the whole stack.

Example Result
1[2 3+]4 1[5]4
1 2] [1 2]
1 2 3[\] 1[3 2]

^ (caret)

1. Exclusive or

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 ^
XOR's two numbers or characters (using the numeric code). Doubles are not supported.

arg1 arg2 Result Example Result
numeric numeric arg1 ^ arg2 5 3^ 6
char char (int) (arg1 ^ arg2) 'D'A^ 5
char numeric (char) (arg1 ^ arg2) 'A3^ 'B

2. Symmetric set difference

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 ^
Finds the unique items that belong to only one of two given arrays/strings, or an array and a number or character (seen as a 1-element array).

arg1 arg2 Result Example Result
array or string array or string symmetric diff. of arg1 and arg2 "hello""hi"^ "eloi"
array or string numeric or char symmetric diff. of arg1 and [arg2] [1 2 1]3^ [1 2 3]
numeric or char array or string symmetric diff. of [arg1] and arg2 'l"hello"^ "heo"

_ (underscore)

Duplicate

Arity: 1 • Notation: postfix • Syntax: arg1 _
Pushes a copy of the value on top of the stack.

arg1 Result Example Result
anything arg1 arg1 "hi"_ "hi""hi"

` (backtick)

String representation

Arity: 1 • Notation: postfix • Syntax: arg1 `
Gets the string representation of a value, i.e. a string that evaluates to the given value.

arg1 Result Example Result
anything string representation of arg1 "hi"` "\"hi\""
1.2` "1.2"
{_}` "{_}"

a

Wrap in array

Arity: 1 • Notation: postfix • Syntax: arg1 a
Takes any value and replaces it with an array containing that value.

arg1 Result Example Result
anything [arg1] 'Aa "A"
[1 2]a [[1 2]]

b

1. Convert to base

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 b
Converts a number to an array of digits in a given base (radix). Negative numbers are converted to their absolute value first. The resulting digits are represented as numbers, not characters.

arg1 arg2 Result Example Result
integer integer array of arg1's digits in base arg2 11 2b [1 0 1 1]
137 10b [1 3 7]
250 16b [15 10]

2. Convert from base

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 b
Converts an array of digits in a given base to a number. The digits may be outside the expected range, the calculation is still done with the same formula. Strings are handled too, using their character codes (e.g. '1' is 49 rather than 1).

arg1 arg2 Result Example Result
array or string integer arg1 converted from base arg2 [1 0 1 1]2b 11
[15 -2]10b 148
integer array or string arg2 converted from base arg1 100"123"b 495051
5[]b 0

c

Convert to character

Arity: 1 • Notation: postfix • Syntax: arg1 c
Converts a value to a character. For strings it takes the first character, and for numbers is gets the character with the given code. Note: these are java-style characters, with codes ranging from 0 to 65535.

arg1 Result Example Result
char arg1 'Ac 'A
string arg1[0] "hello"c 'h
numeric (char)arg1 9786c '☺

d

Convert to double

Arity: 1 • Notation: postfix • Syntax: arg1 d
Converts a value to a double-precision floating point number. For strings it parses the value, and for characters it gets the numeric value as a double.

arg1 Result Example Result
numeric or char (double) arg1 5d 5.0
'ád 225.0
string arg1 parsed as double "1.23e1"d 12.3

e

Scientific notation

Arity: 2 • Notation: infix • Syntax: arg1 earg2
Given a numeric value x and a numeric literal y, calculates x * 10y.

arg1 arg2 Result Example Result
numeric numeric literal arg1 * 10arg2 2.5e3 2500.0
-345e-2 -3.45
2e0.30103 4.000000039936209
1 2+e20 300000000000000000000

Note: e can be followed by another (lowercase) letter or special character and form a 2-character extended operator (will be documented separately)

f

1. For loop

Arity: 3 • Notation: infix • Syntax: arg1 arg2 fvar
Executes a block for each value in an array, storing the value in a given variable rather than pushing it on the stack. If a number is given instead of an array, it is converted to a range.

arg1 arg2 var Result Example Result
array or string block variable name for var in arg1 execute arg2 [5 3]{2X#}fX 32 8
numeric block variable name for var in [0 … arg1-1] execute arg2 3 5{I+}fI 13
block array or string variable name for var in arg2 execute arg1 {A)}"HAL"fA 'I'B'M
block numeric variable name for var in [0 … arg2-1] execute arg1 {12T)/}4fT 12 6 4 3

2. Map with extra parameter

Arity: 3 • Notation: infix • Syntax: arg1 arg2 fop
Takes a binary operator or block literal and applies it to a given value and each item of an array or string, returning an array with the results. Effectively, fop becomes a new binary operator and can be further composed using infix operators.

arg1 arg2 op Result Example Result
array or string anything binary operator or block literal array of (arg1[i] arg2 op) results [4 3]2f+ [6 5]
["hello""hi"]'hf- ["ello""i"]
non-array array or string binary operator or block literal array of (arg1 arg2[i] op) results 10[2 3]f{/2+} [7 5]

g

1. Do-while loop (popping the condition)

Arity: 1 • Notation: postfix • Syntax: arg1 g
Executes a block, pops the top value from the stack and repeats if the value is true (non-zero/not empty).

arg1 Result Example Result
block execute arg1 while the top of the stack (popped) is true 1{A*A(:A}g 3628800

2. Signum

Arity: 1 • Notation: postfix • Syntax: arg1 g
Gets the sign of a number (-1, 0 or 1).

arg1 Result Example Result
numeric sign of arg1 0g 0
-123g -1
1e-9g 1

3. Get from URL

Arity: 1 • Notation: postfix • Syntax: arg1 g
Downloads a page/file from a URL into a string. If the URL doesn't include a protocol part, http is assumed.
This feature is disabled in the online interpreter because it wouldn't work with most sites (due to the same-origin policy).

arg1 Result Example Result
string contents of URL "aditsu.net/hi.txt"g "hello :)"

h

Do-while loop (without popping the condition)

Arity: 1 • Notation: postfix • Syntax: arg1 h
Executes a block, checks the top value from the stack and repeats if the value is true (non-zero/not empty).

arg1 Result Example Result
block execute arg1 while the top of the stack (not popped) is true 18{_2/}h 18 9 4 2 1 0

i

Convert to integer

Arity: 1 • Notation: postfix • Syntax: arg1 i
Converts a value to an integer number. Strings are parsed and characters are converted to their code point.

arg1 Result Example Result
numeric or char (int) arg1 -1.56i -1
'☺i 9786
string arg1 parsed as integer "1234"i 1234

j

1. Memoize (unary)

Arity: 3 • Notation: postfix • Syntax: arg1 arg2 arg3 j
Arity: 1 • Notation: postfix • Syntax: arg1 j
Defines a recursive unary function that caches its results. The first version of j (arity 3) is used for defining the function, and the second version is used inside the function block, for recursive calls. In both cases, the first argument is the unary function argument; the second argument is a value or array of values to be used as (pre-cached) function results for argument values 0, 1, 2…, and the third argument is the function block.

arg1 arg2 arg3 Result Example Result
anything non-array block arg3 applied to arg1, where the result for arg1=0 is arg2 5 1{_(j*}j 120
anything array block arg3 applied to arg1, where the arg2 contains results for arg1=0,1,… 10 2,{(_j\(j+}j 55

2. Memoize (n-ary)

Arity: variable • Notation: postfix • Syntax: arg1 … argn val blk n j
Arity: as defined • Notation: postfix • Syntax: arg1 … argn j
Defines a recursive function of a given arity, that caches its results. The first version of j is used for defining the function, and the second version is used inside the function block, for recursive calls. In both cases, arg1 … argn are the function arguments; val (argument n+1) is a value or (possibly multi-dimensional) array of values to be used as (pre-cached) function results for argument values 0 0…0, 0 0…1 etc, blk (argument n+2) is the function block and n (the last argument) is the function arity.

arg1…argn val blk n Result Example Result
anything anything (value or array) block integer blk applied to arg1…argn, where val specifies pre-cached values 8 3[]{_{1$(1$(j@*\/}{;;1}?}2j 56

Also see this discussion

l

Read line

Arity: 0 • Syntax: l
Reads a line from the input, not including the newline character, and pushes it as a string on the stack. If the end of input is reached, it returns a string containing a single newline (to avoid ambiguity).

Example input Result
foo bar
baz
"foo bar"

m

(Followed by numeric literal) Subtract/remove

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 mnumber
Works like "-", and does not touch the following number.

arg1 arg2 Result Example Result
numeric numeric arg1 - arg2 5 3m4 2 4

Refer to "-" for more examples.

Note: m can be followed by another letter or special character and form a 2-character math operator (will be documented separately)

o

Print

Arity: 1 • Notation: postfix • Syntax: arg1 o
Prints a value to the standard output, removing it from the stack. Array items are printed one after another, with no separator.

arg1 Result Example Output
anything output arg1 ["foo"1.23[4'5]]o foo1.2345

p

Arity: 1 • Notation: postfix • Syntax: arg1 p
Prints the string representation of a value (removing it from the stack) to the standard output, followed by a newline character. It's the same as applying "`" then printing the result and a newline.

arg1 Result Example Output
anything output string representation of arg1 and newline ["foo"1.23[4'5]]p ["foo" 1.23 [4 '5]]

q

Read the whole input

Arity: 0 • Syntax: q
Reads the whole input (until EOF) and pushes it as a string on the stack. If some of the input has already been read, it reads the rest of the input. If the whole input has already been read, it returns the empty string.

Example input Result
foo bar
baz
"foo bar
baz"

r

Read token

Arity: 0 • Syntax: r
Reads the next token from the input (separated by any whitespace) and pushes it as a string on the stack. If the end of input is reached, it returns the empty string.

Example input Result
foo bar
baz
"foo"

s

Convert to string

Arity: 1 • Notation: postfix • Syntax: arg1 s
Converts a value to string. Arrays items are converted individually and then concatenated with no separator.

arg1 Result Example Result
anything arg1 converted to string ["foo"1.23[4'5]]s "foo1.2345"

t

Set array item

Arity: 3 • Notation: postfix • Syntax: arg1 arg2 arg3 t
Sets an array element at a given position. Just like "=", the position wraps around.

arg1 arg2 arg3 Result Example Result
array or string integer anything modified arg1 (arg1[arg2]=arg3) [5 6 7]2 3t [5 6 3]
integer array or string anything modified arg2 (arg2[arg1]=arg3) 4"foo"'xt "fxo"

w

While loop

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 w
Executes a block repeatedly while a condition (given by another block) is true. Similar to "g" except the condition is given separately and is checked at the beginning.

arg1 arg2 Result Example Result
block block while(arg1) execute arg2 3{_}{_(}w 3 2 1 0

z

1. Zip (transpose)

Arity: 1 • Notation: postfix • Syntax: arg1 z
Takes an array viewed as a 2-dimensional matrix (array of rows), and transposes rows with columns. In effect, it returns an array in which the k'th row is an array of all elements in the k'th column or the argument. Rows with different lengths are not truncated,

arg1 Result Example Result
array or string arg1 transposed "hello"z ["hello"]
[[1 2][3 4 5]]z [[1 3] [2 4] [5]]

Note: in the first example, the string is viewed as a matrix of 5 single-character rows, so the result is one row containing the whole string.

2. Abs

Arity: 1 • Notation: postfix • Syntax: arg1 z
Gets the absolute value of a number.

arg1 Result Example Result
numeric abs(arg1) -1.23z 1.23

| (pipe)

1. Bitwise OR

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 |
Performs a bit-by-bit OR on two integers or an integer and a character (through its numeric code).

arg1 arg2 Result Example Result
integer integer arg1 (bitwise) | arg2 7 11| 15
integer char (char) (arg1 | arg2) 3'a| 'c
char integer (char) (arg1 | arg2) 'R67| 'S

2. Set union

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 |
Gets all the items that belong to either one of 2 given arrays/strings, or an array and a number or character (seen as a 1-element array), without duplicates. The order of first occurrence is preserved.

arg1 arg2 Result Example Result
array or string array or string Union of arg1 and arg2 "hello""world"| "helowrd"
array or string numeric or char Union of arg1 and arg2 "hello"'x| "helox"
numeric or char array or string Union of arg1 and arg2 3[2 3 3 4]| [3 2 4]

3. If-else

Arity: 2 • Notation: postfix • Syntax: arg1 arg2 |
Executes a block if a given value is false (zero or empty).

arg1 arg2 Result Example Result
non-block block Execute arg2 if arg1 is false 5 1{)}| 5
5[]{)}| 6

~ (tilde)

1. Bitwise NOT

Arity: 1 • Notation: postfix • Syntax: arg1 ~
Calculates the binary complement of an integer.

arg1 Result Example Result
integer ~arg1 5~ -6

2. Evaluate/execute

Arity: 1 • Notation: postfix • Syntax: arg1 ~
Executes a block, or a string or character parsed as a block.

arg1 Result Example Result
block Evaluate/execute arg1 {1 2+}~ 3
string or char Evaluate/execute arg1 as block "5)"~ 6
'2~ 2

3. Dump array

Arity: 1 • Notation: postfix • Syntax: arg1 ~
Dumps the elements of an array on the stack. Note that it doesn't work for strings, as it evaluates them instead. To dump the characters of a string, use {}/ instead.

arg1 Result Example Result
non-string array Contents of arg1 [1 2 "a"]~ 1 2 "a"