FALSE

Appeared in:
1993
Influenced by:
Influenced:
Paradigm:
Typing discipline:
File extensions:
.f
Versions and implementations (Collapse all | Expand all):
Programming language

FALSE is one of the oldest esoteric languages, ancestor to a whole generation of languages with one-character commands. Unlike most later languages, FALSE provides quite a lot of features, including named variables, strings and lambda-functions.

FALSE was created by Wouter van Oortmerssen in 1993. He had two objectives: creating a confusing APL-style syntax and designing a language as powerful as possible while keeping the compiler as small as possible. At the end the compiler was written in Assembler and took only 1024 bytes. A lot of language elements, including usage of stack as main data structure, were borrowed from Forth.

The language has the following data types: 32-bit integers, strings (can’t be stored in the stack), characters (processed as their ASCII-codes) and boolean values (0 for false and -1 for true). The stack can hold numbers, variable names and functions.

Instructions

S<n> denotes the n-th element off the top of the stack: S0 is the topmost element.

  • number Push this number
  • 'char Push ASCII-code of this character
  • +, -, *, / Push S1+S0, S1-S0, S1*S0, S1/S0
  • _ Unary minus (multiplies S0 by -1)
  • =, > Push -1, if S1=S0 or S1>S0, respectively, and 0 otherwise
  • &, | Push S1&S0, S1|S0; the result is a boolean value (0 or -1)
  • ~ Negation (negate S0)
  • variable name Push this name (not variable value!)
  • :, ; Assignment and value extraction: S0 must be variable name
  • $ Copy S0
  • % Pop S0
  • \ Swap S0 and S1
  • @ Move S2 on top of the stack
  • ø Copy S<S0> to the top of the stack ( is equivalent to $)
  • [...] Push the function in brackets
  • ? Conditional command execution: S1 must be the condition (boolean value), S0 — a function which is executed if the condition is true
  • # while loop: S1 is a function which defines the continuation condition, S0 — a function which is loop body
  • ., , Print S0 as a number/character
  • ^ Read character
  • ß Flush I/O buffers

Elements of syntax:

Non-nestable comments { ... }
Case-sensitivity yes (applies only to variable names anyways)
Variable identifier regexp [a-z]
Variable assignment :
Physical (shallow) equality =
If - then ?

Examples:

Hello, World!:

Example for versions Morphett's FALSE, Wouter's FALSE 1.2.CF

A string is equivalent to a command which simply prints it. There’s no way to put the string on the stack, except for as a part of a function.

"Hello, World!"

Factorial:

Example for versions Morphett's FALSE, Wouter's FALSE 1.2.CF

This example uses iterative method of factorial calculation. Variables i and f store current number (loop counter) and current factorial value. After the variables are initialized, the loop starts. [i;17=~] defines the continuation condition: as long as i doesn’t equal 17. Loop body follows: i and a string constant are printed, i is incremented, old value of f is printed and new value of f is calculated.

For Wouter’s FALSE 1.2.CF factorial values for 13 and above are calculated with overflow error.

0i: 1f: 
[i;17=~]
[i; $."! = " 1+$i: f;$.10, *f:]
#

Fibonacci numbers:

Example for versions Morphett's FALSE, Wouter's FALSE 1.2.CF

This example uses iterative method of calculating Fibonacci numbers. Variables a and b store current numbers, variable i is loop counter.

The second loop empties the stack (deletes Fibonacci numbers written there by the first loop). Some interpreters tolerate data left in stack after program completion, but Wouter’s FALSE requires that the stack is empty and throws a runtime error otherwise.

0i: 1a: 1b:
[i;16=~]
[a; $. ", " $ b; $ a: + b: i;1+i:]
#
"..."

[1=~]
[]
#
%

CamelCase:

Example for versions Morphett's FALSE

The input string is processed character by character. In Morphett’s FALSE strings are entered in a pop-up window, and end of input is marked by an empty line, which is then converted to -1 value. That’s why -1 is used for breaking the loop. Variable s stores “whether the previous character was a space” sign. Conditional commands execution (?) allows to run only if-then conditions; to implement else branch, one has to copy the condition (stored in variable l — whether the current character is a letter), invert it and use another ?.

1_s: ^
[$1_=~]
[ $$ 96> \123\> & [32-]?
  $$ 64> \91\> & $l: [s;~[32+]? , 0s:]? l;~[1_s: %]?
^]
#

Quadratic equation:

Example for versions Wouter's FALSE 1.2.CF

This example is identical to the one written for Morphett’s FALSE, except that in Wouter’s FALSE end of input is signaled by end of line character, which is used for breaking the loop. Besides, % in the end of the code deletes the last leftover value from the stack.

1_s: ^
[$10=~]
[ $$ 96> \123\> & [32-]?
  $$ 64> \91\> & $l: [s;~[32+]? , 0s:]? l;~[1_s: %]?
^]
#
%