Memory and Variables

ABCalc supports so-called memory of unlimited size. The memory consists of memory cells ("variables" in programming). Each memory cell has a distinct name. The names are not case-sensitive, so "A" and "a" denote the same cell (variable).

You use the content of memory cells by specifying their names in expressions in the place of values.

Reserved names

Cells mc0-mc9 are predefined as they are accessible via memory buttons in the ABCalc interface. Also, constants cannot be used for memory cells and cannot be re-assigned.

Storing memory contents

Memory contents are not preserved across sessions; they disappear after you close the application.

Assignment of Values

You can create or update a memory cell by assigning a value to it using ":=" as an assignment operator:

a := 1

or, if the option to use = for assignment is set, simply as

my_cell = 1

Compound Assignment Operators

In addition to the basic := assignment, compound assignment operators combine an operation with assignment. They read the current value of a memory cell, apply the operation, and store the result back:

Operator Equivalent to Description
+= x := x + value Add and assign
-= x := x - value Subtract and assign
*= x := x * value Multiply and assign
/= x := x / value Divide and assign
&= x := x BIT_AND value Bitwise AND and assign
\|= x := x BIT_OR value Bitwise OR and assign
^= x := x BIT_XOR value Bitwise XOR and assign

Examples:

a := 10;
a += 5;   // a is now 15
a -= 3;   // a is now 12
a *= 2;   // a is now 24
a /= 4;   // a is now 6

b := 0b1111;
b &= 0b1010;  // b is now 0b1010 (10)
b |= 0b0001;  // b is now 0b1011 (11)
b ^= 0b0011;  // b is now 0b1000 (8)

Compound assignments are also commonly used as loop counters:

total := 0;
i := 1;
while (i <= 10) { total += i; i += 1; }
total  // 55

Unicode variants ×=, ∙=, and ÷= are available for multiplication and division — see Operators.

Indexed Access

If a memory cell (variable) contains a string or a list, individual elements and slices can be obtained in the same way as they are obtained from values:

mc0 := "abcdefg";
mc0[3] // will yield 'd'
mc0[3..5] // will yield "def"

You can update individual elements of the values contained in memory cells (variables) too:

mc0 := "abcdefg";
mc0[3] := 'X';
mc0[2..4] // will yield 'cXe'