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
ArgumentsResultExample
numbernumberArithmetic addition of arguments2 3+5
arrayarrayArray concatenation[1 2][3 4]+[1 2 3 4]
stringstringText concatenation'test''this'+'testthis'
blockblockBlock concatenation'test'{123}+{test 123}

-

Arguments: 2, coerced
ArgumentsResultExample
numbernumberArithmetic substraction of arguments2 3--1
arrayarrayRemoves from first array elements that are in second[1 2][3 1]-[1]

*

Arguments: 2, ordered
ArgumentsResultExample
numbernumberArithmetic multiplication of arguments2 3*6
arraynumberCreates array that is a multiple copy of original2[1 2]*[1 2 1 2]
arrayarrayJoin array using second array as separator[1 2 3][4 5]*[1 4 5 2 4 5 3]
stringarrayJoin array using separator[1 2]','*'1,2'
stringstringUse first string as an array and second as separator'test'','*'t,e,s,t'
blocknumberExecutes block given number of times2{3}*3 3 3
blockarrayFold, reduce array to single value using block[1 2 3 4]{+}*10

/

Arguments: 2, ordered
ArgumentsResultExample
numbernumberArithmetic division of arguments2 3/0.667
arraynumberSplit into groups[1 2 3 2 4]2/[[1 2][3 2][4]]
arrayarraySplit array around matches[1 2 3 2 4][2]/[[1] [3] [4]]
blockarrayExecute block for each argument in array[1 2 3]{.}/1 1 2 2 3 3
blockblockUnfold, while first block yields true execute second block and gather results into array0 1 {20<}{.@+} /13 [1 1 2 3 5 8 13]

%

Arguments: 2, ordered

How to input: Long click on *
ArgumentsResultExample
numbernumberArithmetic modulo of arguments7 3%1
arraynumberTake every n-th element from array[1 2 3 4 5]2%[1 3 5]
stringstringSplit string around matches, drop empty elements't,e,s,t'','%['t' 'e' 's' 't']
blockarrayMap. 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 +
ArgumentsResultExample
numberGet n-th element from stack1 2 3 4 2$2
arraySort array elements[5 3 1 6 2]$[1 2 3 5 6]
stringSort letters in string'test'$'estt'
blockarraySort array using block as mapping[5 3 1 6 2]{-1*}$[6 5 3 2 1]

,

Arguments: 1

How to input: Long click on ;
ArgumentsResultExample
numberCreate array from 0 to given number5,[0 1 2 3 4]
arrayGet length of an array[0 1 2 3 4],5
blockarrayFilter. 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 -
ArgumentsResultExample
numberBitwise negate given number5~-6
arrayPop array values onto stack[1 2 3]~1 2 3
stringEvaluate string as script'1 2+'~3
blockExecute block{1 2+}~3

?

Arguments: 2, ordered

How to input: Long click on .
ArgumentsResultExample
numbernumberRaise number to given power2 8?256
arraynumberGet index of element[1 2 3 4]2?1
blockarrayGet element that first passes given condition[1 2 3 4]{2%}?1

|

Arguments: 2, ordered

How to input: Long click on 7
ArgumentsResultExample
numbernumberBitwise OR2 8|10
arrayarraySet union[1 2 3][2 4]|[1 2 3 4]

&

Arguments: 2, ordered

How to input: Long click on 8
ArgumentsResultExample
numbernumberBitwise AND2 8&0
arrayarraySet intersection[1 2 3][2 4]&[2]

^

Arguments: 2, ordered

How to input: Long click on 9
ArgumentsResultExample
numbernumberBitwise XOR2 8^10
arrayarraySet symmetric difference[1 2 3][3 4]^[1 2 4]

<

Arguments: 2, ordered

How to input: Long click on [
ArgumentsResultExample
numbernumberCompare values2 8<1
arraynumberGet first n elements of an array[1 2 3]2<[1 2]
stringstringCompare values'test''abc'<0

>

Arguments: 2, ordered

How to input: Long click on ]
ArgumentsResultExample
numbernumberCompare values2 8>0
arraynumberRemove first n elements from an array[1 2 3]2>[3]
stringstringCompare values'test''abc'>1

=

Arguments: 2, ordered

How to input: Long click on =
ArgumentsResultExample
numbernumberCompare values2 8=0
arraynumberGet element of given index, -1 if not found[1 2 3]2=3
stringstringCompare values'test''abc'=0

(

Arguments: 1

How to input: Long click on {
ArgumentsResultExample
numberDecrement value8(7
arrayExtract first element from array[1 2 3](1[2 3]

)

Arguments: 1

How to input: Long click on }
ArgumentsResultExample
numberIncrement value8)9
arrayExtract last element from array[1 2 3](3[1 2]

`

Arguments: 1

How to input: Long click on
ArgumentsResultExample
anyConvert to string8`'8'

!

Arguments: 1

How to input: Long click on :
ArgumentsResultExample
anyNegate value. 0, [], '' and {} will result in 1, otherwise 08!0

.

Arguments: 1
ArgumentsResultExample
anyDuplicate value on top of the stack[1 2 3].[1 2 3][1 2 3]

@

Arguments: 3

How to input: Long click on 0
ArgumentsThird argumentResultExample
anyanyanyRotate arguments on top of the stack. Extract third argument to the top.1 2 3@2 3 1

\

Arguments: 2

How to input: Long click on /
ArgumentsResultExample
anyanySwap two arguments on top of the stack.1 2 3\1 3 2

;

Arguments: 1
ArgumentsResultExample
anyRemove top of the stack.1 2 3;1 2

[

Arguments: 0
ArgumentsResultExample
(none)Marks position of the stack for slicing.[1 2 3][1 2 3]

]

Arguments: 0
ArgumentsResultExample
(none)Slices stack where it has been marked.[1 2 3][1 2 3]

abs

Arguments: 1
ArgumentsResultExample
numberReturns absolute value of an number.-3abs3

and

Arguments: 2
ArgumentsResultExample
anyanyLazy and - returns first argument if it's falsy otherwise returns second.4 {1.} and1 1

or

Arguments: 2
ArgumentsResultExample
anyanyLazy or - returns first argument if it's truthy otherwise returns second.4 {1.} or4

xor

Arguments: 2
ArgumentsResultExample
anyanyExclusive or - returns one of the arguments that is truthy. If both are truthy returns 0.4 {1.} xor1 0

do

Arguments: 1
ArgumentsResultExample
blockExecutes block, pops a value from the stack, if it's truthy then repeat.5{1-..}do4 3 2 1 0 0

if

Arguments: 3
ArgumentsResultExample
anyanyanyIf first argument is truthy then execute second, otherwise execute third.5 1 {2 0/}if1

while

Arguments: 2
ArgumentsResultExample
blockblockExecutes first block (condition). If result is truthy then execute second. Repeat.5{.}{1-.}while4 3 2 1 0 0

until

Arguments: 2
ArgumentsResultExample
blockblockExecutes first block (condition). If result is falsy then execute second. Repeat.5{.}{1-.}until5

rand

Arguments: 1
ArgumentsResultExample
numberReturns a random number from 0 up to (but not including) given number.5rand3

zip

Arguments: 1
ArgumentsResultExample
arraySwap array rows with columns.[[1 2][3 4][5 6]]zip[[1 3 5][2 4 6]]

pi

Arguments: 0
ArgumentsResultExample
(none)Returns a value of π.pi3.141

sin

Arguments: 1
ArgumentsResultExample
numberReturns a math sine value for given number.0.3sin0.296

cos

Arguments: 1
ArgumentsResultExample
numberReturns a math cosine value for given number.0.3cos0.955

tan

Arguments: 1
ArgumentsResultExample
numberReturns a math tangent value for given number.0.3tan0.309

asin

Arguments: 1
ArgumentsResultExample
numberReturns an inverse math sine value for given number.0.296asin0.3

acos

Arguments: 1
ArgumentsResultExample
numberReturns an inverse math cosine value for given number.0.3acos1.266

atan

Arguments: 1
ArgumentsResultExample
numberReturns an inverse math tangent value for given number.0.995atan0.782

sinh

Arguments: 1
ArgumentsResultExample
numberReturns a math hyperbolic sine value for given number.0.3sinh0.304

cosh

Arguments: 1
ArgumentsResultExample
numberReturns a math hyperbolic cosine value for given number.0.3cos1.045

tanh

Arguments: 1
ArgumentsResultExample
numberReturns a math hyperbolic tangent value for given number.0.3tanh0.291

e

Arguments: 0
ArgumentsResultExample
(none)Returns a value of E.e2.718

ln

Arguments: 1
ArgumentsResultExample
numberReturns a value of natural logarithm.e ln1

log

Arguments: 2
ArgumentsResultExample
numbernumberReturns a value of logarithm for given number and base.32 2log5

exp

Arguments: 1
ArgumentsResultExample
numberRaises E to a given power. Equivalent of e x?.2exp7.389

sum

Arguments: 1
ArgumentsResultExample
arrayReturns a sum for all numbers in array.[1 2 3] sum6

base

Arguments: 2
ArgumentsResultExample
numbernumberConvert number to different base.6 2 base[1 1 0]
arraynumberInterprets an array as a number in given base.[1 1 0] 2 base6

hex

Arguments: 1
ArgumentsResultExample
numberConverts a number to a hexadecimal string.123hex'x7b'

bin

Arguments: 1
ArgumentsResultExample
numberConverts a number to a binary string.123bin'b1111011'

oct

Arguments: 1
ArgumentsResultExample
numberConverts a number to an octal string.123oct'o173'

dec

Arguments: 1
ArgumentsResultExample
stringConverts a string from hexadecimal, binary or octal format to a number.'xcafe'dec51966