Foo

Foo is an esoteric programming language, created by User:Feky in February 2008.
It is inspired mainly by Brainfuck.
== 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.
== 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.
Cmd 	Description
" 	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 by a number, like &55, the cell will be set to that number. If not, it will be set to a popped value from the stack.
@ 	Similar to the & operator, but this one pushes values onto 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 a decimal integer (i), hexadecimal integer (h) and ASCII character (c). If the mode isn't specified, a standard Foo interpreter will show an error message and continue execution. For example, $h will print the current cell in hex, and $c100 will print d.
+ -* /%	Arithmetic operators. These are always applied to the currently pointed to element in the array. For example, +10 will add 10 to the current element, and / will divide the element by a value popped from the stack.
# 	Pause the execution of the program (sleep) for the specified number of seconds. If no number is given after #, use the value of the current cell.
( 	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 from the number specified. If there's no number after (, the loop will execute while the value of the current cell is not equal to zero.
) 	Conditional jump (end of a loop). Jumps back to the last ( if the value of the current cell isn't equal to the value on the top of the loop stack, or else continues the program execution normally.
== 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
Decimal to binary converter (big-endian order):
 &255(0@>&%2$i</2)
Fibonacci numbers:
 "0 1 "&1>>>(20<<@>+<<@>>+<<@>&>@<<&>>$i$c32&0>+1)
4-dimensional loop:
 (4+1"Time: "$i$c10>(6+1>(3+1>(3+1$i$c32)&0<$c10)&0<$c10)&0<)
99 bottles of beer (Without support for singular form of "bottles"):
 &100(1 -1 $i " bottles of beer on the wall, " $i " bottles of beer." $c10 -1 "Take one down and pass it around, " $i " bottles of beer on the wall." +1 $c10$c10)
 "No more bottles of beer on the wall, no more bottles of beer." $c10 "Go to the store and buy some more, 99 bottles of beer on the wall."$c10$c10
==See also==
* Brainfuck
==External resources==
* A Foo interpreter written in C
Category:Languages
Category:Cell-based
Category:Low-level
Category:2008
Category:Implemented
Category:Output_only