FALSE

From Wikipedia, the free encyclopedia
Jump to: navigation, search
FALSE
Developer Wouter van Oortmerssen
Appeared in 1993 (1993)
Influenced by Forth
Influenced Brainfuck, Befunge
Website strlen.com

FALSE is an esoteric programming language designed by Wouter van Oortmerssen in 1993, named after his favorite Boolean value. It is a small Forth-like stack-oriented language, with syntax designed to make the code inherently obfuscated, confusing, and unreadable. It is also noteworthy for having a compiler of only 1024 bytes (written in 68000 assembly). According to Van Oortmerssen, FALSE provided the inspiration for various well-known esoteric languages, including brainfuck and Befunge.

FALSE is notably more tractable than most esoteric programming languages. The fundamental operations that it provides are reasonably sensible, and there is no gratuitous complexity. In these respects it stands in strong contrast to the behemoths Intercal and Malbolge. The difficulty of programming in FALSE comes mostly from the low-level nature of the language, which has the feel of a Forth-like assembly language. The remainder of the language's awkwardness comes from the concise punctuation-based syntax, which many people find more difficult than a more conventional word-based syntax.

The language features basic arithmetic and logical operations, variables, subroutines, control flow statements, and input/output operations. FALSE operations are done using a stack. Its structure is largely based on the Forth programming language.

The stack[edit]

Everything in the language is defined by how it operates on the stack. When a value is encountered, it is simply pushed onto the stack; when an operator is encountered, a number of operands are popped from the stack, the operation is performed on them, and some number of results are pushed back onto the stack. For example, in the expression 1 3_+:

1 : pushes the integer 1 onto the stack
3 : pushes the integer 3 onto the stack
_ : pops 3 from the stack, negates it, and pushes -3
+ : pops 1 and -3 from the stack and pushes their sum, -2.

Subroutines also act on the stack – this is the way that they are given arguments and return values; they see the same stack as the rest of the program.

Data types[edit]

Data types that can be used in the program are ASCII characters (which are preceded by ' (single-quote)), 32-bit integers, boolean values (0 representing false; -1 representing true), and subroutines. These can be used on the stack or stored in variables.

Basic operators[edit]

FALSE supports binary and unary operations in reverse Polish notation, as well as operations that act on the stack alone.

Arithmetic operators are +, -, *, and / (binary operators, which pop two elements from the stack and push (respectively) their sum, difference, product, or quotient) and the _ (underscore) is unary negation (which pops one element and pushes its negation).

Logical operators are =, >, &, | (binary operators of equality, greater than, logical conjunction, and logical disjunction), and ~ (unary logical negation).

Stack operators are (with examples of form example inputresulting stack):

  • $ - Duplicates the topmost element of the stack: 0 1$0 1 1
  • % - Deletes the topmost stack element: 0 1%0
  • \ - Swaps the two topmost stack elements: 0 1 2\0 2 1
  • @ - Rotates the third stack item to the top: 0 1 2 3@0 2 3 1
  • ø - Pick: Copies the n-th stack item to the top: 7 8 9 2ø7 8 9 7

Variables[edit]

Variables are single lowercase alphabetical characters (a-z). All variables are global. : (colon) sets a variable to the value at the top of the stack (i.e., 3a: assigns the value 3 to the variable a) and ; (semicolon) reads their values (i.e., a; would push 3 onto the stack if a has been assigned 3). The heavy use of the stack in FALSE eliminates a great deal of need for variables, and they are mainly used with subroutines.

Subroutines[edit]

Subroutines are first class, and are pieces of code contained between [ and ]. The "apply" operator is !. It takes the subroutine on top of the stack and runs it. Note that if the value on top of the stack is not a subroutine, the program will behave abnormally.

A very basic example subroutine:

3[1+]!

This pushes 3 on the stack, pushes the expression [1+] (which takes the current stack and increments the top value by 1), and applies this to 3, leaving the stack as 4.

Control flow[edit]

FALSE has two control flow statements, if and while.

If[edit]

The "if" operator is ?. It takes the two top stack elements, the top being a subroutine; the second being a boolean, and runs the subroutine if the boolean is true.

For example,

a;1=[3b:]?

tests if the variable a is equal to 1, and if so, runs the expression [3b:] which assigns 3 to b.

While[edit]

The "while" operator is #. It takes the top two stack elements, both subroutines, and continually evaluates the second element, then the top element, until the second one stops returning true (that is, leaving a true boolean on top of the stack).

For example,

[a;1=][2f;!]#

runs the expression [2f;!] (which puts 2 on the stack and runs whatever lambda expression is contained in the variable f) for as long as the variable a is equal to 1.

Strings[edit]

Strings are not a real data type in FALSE; they only exist as string literals and cannot be stored directly on the stack nor in variables, and cannot be modified. However, they can be contained within subroutines (which can be stored). When a string is encountered it is simply printed as output. Strings are any character sequence between double-quotes (""), including newlines. So, a program consisting simply of

"Hello world!
"

would print "Hello world!" followed by a new line.

Subroutines can contain strings. For example:

a;1=["true"]?

would print "true" if the variable a is equal to 1.

Input / Output[edit]

Apart from strings, which print themselves, FALSE has a number of operators for input/output from and to standard streams.

  • . (period) prints the topmost stack item out as an integer.
  • , (comma) prints out the topmost stack item as an ASCII character.
  • ^ reads a single character from standard input and pushes it on the stack.
  • ß flushes both standard input and standard output streams.

Comments[edit]

Comments are delimited by { and }. Comments cannot be nested.

Code examples[edit]

Sample programs taken from the FALSE Programming Language web page:

Hello world:

"Hello world!
"

File copy utility. Usage: copy < infile > outfile

ß[^$1_=~][,]#

Factorial calculator for numbers 1 through 8:

[$1=~[$1-f;!*]?]f:          { fac() in FALSE }
"calculate the factorial of [1..8]: "
ß^ß'0-$$0>~\8>|$
"result: "
~[\f;!.]?
["illegal input!"]?"
"

Write all prime numbers up to 100:

99 9[1-$][\$@$@$@$@\/*=[1-$$[%\1-$@]?0=[\$.' ,\]?]?]#

See also[edit]

External links[edit]