42

One day, at school, I overheard some people talking about math homework, and getting problems wrong on said homework. One of them suggested that the number they got as an answer was actually a variable that stood for the correct answer... which gave me an idea.

Statements

Statements are entered one-per-line. Each statement consists of some expression (described below). Some expressions are special:

Expressions

In order of precedence:

Numbers, π, , Ø
Numeric constants. If the number is a variable (created with :), it will be replaced with its value. The replacement only happens once, when the number is directly in the code (i.e., not a result of an expression); for example, if the variable 5 has the value 6 and the variable 6 has the value 7, typing 5 will give the value 6, not 7; likewise, typing 2+3 will give the value 5, not 6 or 7. π, , and Ø (uppercase O with slash) respectively give pi, infinity, and not-a-number.
The JavaScript version also accepts (empty set) for Ø, and τ for 2π.
[expression]
Finds the value of the variable given by the result of the expression. Continuing the example above, [5] would give 7, and [2+3] would give 6. If the variable has not been assigned, the brackets don't do anything.
-
Negates the following expression. Note that -2 negates the value of the variable 2, rather than finding the value of the variable -2.
^
Raises a number to a power. If no number is given on the left, the constant e (or its value) is used. If the prefix form is used after an operator of equal or higher precedence, the result is undefined.
*, /, %
Multiplication, division, and modulo, respectively. If no number is given on the left of /, 1 is used instead. If the prefix form of / is used after an operator of equal or higher precedence, the result is undefined.
+, -
Addition and subtraction.
=, , <, , >,
Compare. Gives the value of 1 for true and 0 for false.
&, |, !
And, or, not, respectively. The second operand of & and | is only evaluated if necessary.
:
Variable assignment: Replace all instances of the number on the left with the number on the right. If the left-hand side of the : operator is a number or a bracketed expression, one less level of indirection is used than normal. Reassigning 0 or 1 will change how math works; assigning 0 and 1 to the same value is not recommended.

Any character not mentioned above (including all letters, apostrophe, and comma) is treated as whitespace.

Interpreter

Old Java version: Applet, Download (125 KB), Download source (19 KB) (downloads also include Try and CLWPA)