O

O, previously name Fifth, is a stack-based language based off Forth and GolfScript. It is read character by character like Fish, Befunge, and Refract, but it is only one dimensional. It was made in July, 2015, by User:Phase. You can find a more up-to-date version of the language on ReadTheDocs or try it out online.

Syntax
Code is read character by character, with each one doing different things. Spaces are not needed unless you set it to a variable or codeblock.

Hello World
"Hello, World!"o

Factorial
[i#,;]*o Gets input from stdin and outputs to stdout. Explanation: [       Start making an array i#     Store the input from the user to an array ,;   Store list from 1 to input in the array ]  Push the array to the stack *o Output all the contents of the array multiplied together

Cat
io

Function definition
{.*}:s This squares the top of the stack.

Repeat a string
"ha"5*4{+}o Prints "hahahahaha"

The sum of the cubes of a list from 1 to n
[i#,]3^+o This takes a list from 0 to  (  being the input) and squares each value, then adds them together.

The Stack
You can push &amp; pop things from the stack, as well as manipulate the items on it,

Strings
To push a string, you use quote marks.

&quot;Hello, World!&quot;

Characters
Characters are stored as strings on the stack, so you can manipulate them the same way. Here's how you push a single character: 'h o This prints  as if it were a string (because it is).

Numbers
Numbers are written in base 36, from 0 to Z. This pushes,  , and. They are saved in the stack as s.

23Z

Together, now
'H"ello, World!"2345

Stack contents:
 * 5
 * 4
 * 3
 * 2
 * ello, World!
 * H

Popping
is used to pop the top value off the stack.

23;4

Stack contents:
 * 4
 * 2

Stack manipulation

 * clones the top of the stack
 * swaps the top to values on the stack
 * moves the third value on the stack to the top
 * reverses the stack
 * pushes the length of the stack to the stack
 * pops the top value and prints it
 * gets input from stdin and pushes it as a string

String manipulation
all do normal math for numbers, but they do special things for strings.

For the next examples, we'll assume  and   are the two objects on the top of the stack,   on top of , like:
 * b
 * a

+
If a or b is a string, concatenate. 5"Test"+o Prints, as numbers are stored as doubles.

-
If a or b is a string, removeAll. "Hello&World&Hi" '& -o Prints

*
If a xor b is a string, duplicate. "He"5* This pushes  to the stack 5 times, so the stack is:
 * He
 * He
 * He
 * He
 * He

does the same thing.

/
If a or b is a string, split. "A_B_C_D_E_F" '_ / This splits the string and pushes each substring in reverse order (or normal depending on how you're viewing it):
 * F
 * E
 * D
 * C
 * B
 * A

%
String replacement, only works if the top two elements are strings. "This sucks" "sucks" "rocks" % o Prints.

#
This only takes in one argument, called s. It tries to parse s as a double and pushes it to the stack. If it's not a double, it returns the hashcode of the string.

"5.01"# Pushes  to the stack as a double.

"abc"# Pushes the hascode of.

~
evaluates the string as code. "55+"~ This parses each character in the string and pushes 10 to the stack.

Boolean logic
There are many logic operations that can be used on strings and numbers. If one object is a number and the other is a string, the number will be casted to a string and compared like strings.

Pushes 1 if the two items are equal. 22=o Prints 1

"2" "2" =o Prints 1

2 "2" = o Prints 1

2 "1" =o Prints 0

Numbers
Pushes 1 if the first item is less than the second item. Both item are casted to strings. 22o Prints 0

21>o Prints 1

Strings
turns into contains if one of the arguments is a string. '2 "234" >o Prints 1

3 "333" >o Prints 1

CodeBlocks
CodeBlocks are surrounded by  and are pushed to the stack. You can then assign them to variables with. Calling the variable that holds the CodeBlock again will run the block. A CodeBlock will stay on the stack until it is popped off or used in a function/operator/CodeBlock. CodeBlocks can be popped off like every other object and variables that are assigned to them will stay assigned to them. {.*}:s;5s This creates a block called  that squares a number. is pushed and then the square block is called.

CodeBlocks can be set to any character, including spaces and unicode characters. {'s}: ; oo This prints   twice.

CodeBlocks can also overwrite operators, like variables. {;}:.;6.o Throws an error because  is set to pop.

+
Adding CodeBlocks will have different effects depending on the arguments. {1} "234+++" + This will concatenate the string into the CodeBlock's code.

{5}5+ This does the same as above, including using the second argument as a string.

"1234**o" {5o} This also does the same as above, except the string is added to the end of the CodeBlock code, so running this would print.

Variables
Variables hold one value that can be pushed to the stack. To make a variable, you use. This will take the value on the top of the stack and set the variable's value to it.

4:C is now set to. This will override any numbers, so using  won’t push   anymore, it will push. You can use any Unicode characters, but they will add to you byte count.

To push the value of a variable, you just have to use it as an operator.

4:k;kk+ The stack now holds :


 * is pushed
 * the value of  is set to
 * is popped off
 * is pushed twice, putting two s on the stack
 * the two s are added together, leaving

To change the value of a variable, you just have to reassign it to the top of the stack using.

4:l;5:l;ll* The top of the stack is now.

Arrays
Arrays are made with. [1 2 3] Arrays can contain any object except other lists.

+
To add lists together, you use. [1 2 3] [4 5 6]+

`
You can get the nth item of a list using [1 2 3 4 5] 2` Pushes 3, since it starts from zero.

Dictionaries
Dictionaries are made with. It will pop everything off the stack and store them in a Dictionary object witch can be modified and manipulated. The stack size must be an even number for everything to be put in the stack. 'a 5 'b 6 & This creates a dictionary with keys  and   and values   and.

`
To get a value from a dictionary, you have to supply a key and use 'a ` Pushes 5 to the stack.

+
You can add dictionaries together using. 'a 1 'b 2 'c 3 & 'd 4 'e 5 'f 6 & +

If statements
If statements are made in the form  by using. 1 {"true"o} {"false"o} ? An object will trigger the 'true' block if it is:
 * String -> not equal to ""
 * double -> not equal to zero
 * CodeBlock -> run the block, pop the top value: check if the top value is true
 * Array -> size is not equal to zero
 * Dictionary -> keyset size is not equal to zero

If the object returns false, it will run the false CodeBlock.

For loops
For Loops are renamed to "Do Loops", as in "do {block} x amount of times", because  was already taken for File I/O. 5 {'%o} d This will run the CodeBlock 5 times and print.

While loops
This will pop the top of the stack. If that value is true, run the CodeBlock. A.{1-..o' o} w This will print. There are a lot of s because   pops the stack each time it runs.

HTTP server
To make an http server, you use.

&quot;C:\index.html&quot;ZZ*h This creates a server using the index file located in the C drive; the port is set to.

File I/O
puts the interpreter into file mode, meaning the next command does something with files.

Getting data from a file
Let's say you have a file named  and you want to get the text from that file. You can using

contains: I like cheese

We'll use this to push the contents of the file to the stack (assuming that  is in the same directory): "stuff.txt"fi The stack now contains the string "I like cheese".

Putting data in a file
Using, we can overwrite whatever is in a file with what is on the stack. "I don't like cheese""stuff.txt"fo Anything that was in  is now gone, and it only contains "I don't like cheese". will only put the second item on the stack into the file, no other elements will be affected.

External resources

 * Current interpreter