Calcscript

Operators

Most of the operators have more than one overload and act
differently depending on arguments on stack. Arguments
additionaly can be ordered or coerced.
Types in Calcscript have priority, from the lowest to
highest: number, array, string and block. Ordering takes two
arguments from the stack, sorts them according to their
priority and places them back on stack. Coercing converts
arguments to be of the same type - argument with lower
priority will be converted to match the second one.

When converting to boolean value,
0
,
[]
,
''
and
{}
are considered falsy. Everything else is truthy.

+

Arguments: 2, coerced

Arguments

Result

Example

number

number

Arithmetic addition of arguments

2 3+

5

array

array

Array concatenation

[1 2][3 4]+

[1 2 3 4]

string

string

Text concatenation

'test''this'+

'testthis'

block

block

Block concatenation

'test'{123}+

{test 123}

-

Arguments: 2, coerced

Arguments

Result

Example

number

number

Arithmetic substraction of arguments

2 3-

-1

array

array

Removes from first array elements that are in
second

[1 2][3 1]-

[1]

*

Arguments: 2, ordered

Arguments

Result

Example

number

number

Arithmetic multiplication of arguments

2 3*

6

array

number

Creates array that is a multiple copy of
original

2[1 2]*

[1 2 1 2]

array

array

Join array using second array as separator

[1 2 3][4 5]*

[1 4 5 2 4 5 3]

string

array

Join array using separator

[1 2]','*

'1,2'

string

string

Use first string as an array and second as
separator

'test'','*

't,e,s,t'

block

number

Executes block given number of times

2{3}*

3 3 3

block

array

Fold, reduce array to single value using block

[1 2 3 4]{+}*

10

/

Arguments: 2, ordered

Arguments

Result

Example

number

number

Arithmetic division of arguments

2 3/

0.667

array

number

Split into groups

[1 2 3 2 4]2/

[[1 2][3 2][4]]

array

array

Split array around matches

[1 2 3 2 4][2]/

[[1] [3] [4]]

block

array

Execute block for each argument in array

[1 2 3]{.}/

1 1 2 2 3 3

block

block

Unfold, while first block yields true execute
second block and gather results into array

0 1 {20<}{.@+} /

13 [1 1 2 3 5 8 13]

%

Arguments: 2, ordered

How to input: Long click on
*

Arguments

Result

Example

number

number

Arithmetic modulo of arguments

7 3%

1

array

number

Take every n-th element from array

[1 2 3 4 5]2%

[1 3 5]

string

string

Split string around matches, drop empty
elements

't,e,s,t'','%

['t' 'e' 's' 't']

block

array

Map. Execute block for each argument in array
and gather results

[1 3 5]{2*}%

[2 6 10]

$

Arguments: 1

How to input: Long click on
+

Arguments

Result

Example

number

Get n-th element from stack

1 2 3 4 2$

2

array

Sort array elements

[5 3 1 6 2]$

[1 2 3 5 6]

string

Sort letters in string

'test'$

'estt'

block

array

Sort array using block as mapping

[5 3 1 6 2]{-1*}$

[6 5 3 2 1]

,

Arguments: 1

How to input: Long click on
;

Arguments

Result

Example

number

Create array from 0 to given number

5,

[0 1 2 3 4]

array

Get length of an array

[0 1 2 3 4],

5

block

array

Filter. Get elements from array that return
true when executed by block

[0 1 2 3 4]{2%},

[1 3]

~

Arguments: 1

How to input: Long click on
-

Arguments

Result

Example

number

Bitwise negate given number

5~

-6

array

Pop array values onto stack

[1 2 3]~

1 2 3

string

Evaluate string as script

'1 2+'~

3

block

Execute block

{1 2+}~

3

?

Arguments: 2, ordered

How to input: Long click on
.

Arguments

Result

Example

number

number

Raise number to given power

2 8?

256

array

number

Get index of element

[1 2 3 4]2?

1

block

array

Get element that first passes given condition

[1 2 3 4]{2%}?

1

|

Arguments: 2, ordered

How to input: Long click on
7

Arguments

Result

Example

number

number

Bitwise OR

2 8|

10

array

array

Set union

[1 2 3][2 4]|

[1 2 3 4]

&

Arguments: 2, ordered

How to input: Long click on
8

Arguments

Result

Example

number

number

Bitwise AND

2 8&

0

array

array

Set intersection

[1 2 3][2 4]&

[2]

^

Arguments: 2, ordered

How to input: Long click on
9

Arguments

Result

Example

number

number

Bitwise XOR

2 8^

10

array

array

Set symmetric difference

[1 2 3][3 4]^

[1 2 4]

<

Arguments: 2, ordered

How to input: Long click on
[

Arguments

Result

Example

number

number

Compare values

2 8<

1

array

number

Get first n elements of an array

[1 2 3]2<

[1 2]

string

string

Compare values

'test''abc'<

0

>

Arguments: 2, ordered

How to input: Long click on
]

Arguments

Result

Example

number

number

Compare values

2 8>

0

array

number

Remove first n elements from an array

[1 2 3]2>

[3]

string

string

Compare values

'test''abc'>

1

=

Arguments: 2, ordered

How to input: Long click on
=

Arguments

Result

Example

number

number

Compare values

2 8=

0

array

number

Get element of given index, -1 if not found

[1 2 3]2=

3

string

string

Compare values

'test''abc'=

0

(

Arguments: 1

How to input: Long click on
{

Arguments

Result

Example

number

Decrement value

8(

7

array

Extract first element from array

[1 2 3](

1[2 3]

)

Arguments: 1

How to input: Long click on
}

Arguments

Result

Example

number

Increment value

8)

9

array

Extract last element from array

[1 2 3](

3[1 2]

`

Arguments: 1

How to input: Long click on
⇧

Arguments

Result

Example

any

Convert to string

8`

'8'

!

Arguments: 1

How to input: Long click on
:

Arguments

Result

Example

any

Negate value. 0, [], '' and {} will result in
1, otherwise 0

8!

0

.

Arguments: 1

Arguments

Result

Example

any

Duplicate value on top of the stack

[1 2 3].

[1 2 3][1 2 3]

@

Arguments: 3

How to input: Long click on
0

Arguments

Third argument

Result

Example

any

any

any

Rotate arguments on top of the stack. Extract
third argument to the top.