Foo

From Esolang

Jump to: navigation, search

Foo is an esoteric programming language, created by Feky in February 2008. It is inspired mainly by Brainfuck, and is Turing-complete (since Brainfuck is).

Contents

[edit] Memory

Foo programs are supplied with a one-dimensional array of X elements (cells, whatever), where each element can hold a value from 0 to 65535. The array pointer wraps around when it exceeds the number X, and points to the first element in the array. All elements in the array are initialized to zero on the start of the program. There's also a stack to help with arithmetic operations and various copying operations, which can also have a custom number (X) of elements, and the value of each can vary from 0 to 65535. Conditional jumps (loops) are also controlled using a stack, that is limited to the number of maximum nested loops.

[edit] Operators

Foo is capable of doing basic arithmetic operations (of course), measuring the time (in seconds, and larger units), controlling the flow of execution and outputting values. Foo programs end when the interpreter reaches EOF.

" - Everything between these will be printed to stdout (or somewhere else).

& - Set the value of the currently selected cell in the array to some other value. If followed numbers, like '&55', the cell will be set to 55. If not, it will be set to a popped value from the stack.

@ - Similar to the '&' operator, but this one pushes values on the stack.

< - Decrement the array pointer by one.

> - Increment the array pointer by one.

$ - Print out a single value. There are 3 modes - print as an integer (i), hexadecimal integer (h) and ASCII character (c). If the mode isn't specified, a standard Foo interpreter will show and error and continue execution. For example, '$h' will print the current cell in hex, and '$c100' will print 'd'.

+, -, *, /, % - Arithmetic operators. They are always applied to the currently pointed element in the array. For example, '+10' will add 10 to the current element, and '/' will divide the element with a value popped from the stack.

# - Pause the execution of the program (sleep) for specified seconds. If no number is given after '#', it get the value of the current cell and sleep that much.

( - Beginning of a loop. If followed by a number, the loop will be executed as long as the value of the current cell is different than the number specified. If there's no number after '(', the loop will execute while the cell is not equal to zero.

) - Conditional jump (end of a loop). Jumps back to the last '(' if the current cell isn't equal to the value on the top of the loop stack, or continues the program execution normally.

[edit] Example code

The simplest Hello World program:

   "Hello, World!"

Double an integer and print it:

   &256*2$i

Countdown loop:

   &10(0#1-1$i$c10)"boom!"$c10

Infinite loop:

   (1)

Negative numbers:

   &30@50-@&65535-+1$i

Factorial calculator (works if the number is less than 9):

   &4>&1<(0@-1>*<)>$i

[edit] See also

[edit] External resources

Personal tools