Φ

Created by User:Rphii in 2021.
== Idea ==
You can finally use the golden ratio for programming!
The idea is to rely on the letter φ as much as possible, be it visually similar or what not.
It mainly uses a one dimensional array and it should still give the user as much low-level control over that memory as possible.
The φ-language is partly inspired by the golden ratio.
== Version ==
1.0.2
== Memory ==
* Each program in φ uses a chunk of memory. By default it is of size 4096 bytes.
=== initialization ===
* Every index that is a multiple of 8 shall be initialized to φ, the golden ratio with double precision (8 bytes per φ)
* When the memory size is adjusted, memory shall also be initialized properly
* the float section is related to that
== Instructions ==
=== [element] ===
Command 	Description
Φ([index]) 	Access from or to index within array
φ([source]) 	Access from or to source (various, see below)
φ([source],[mode]) 	Access from or to source with a specified mode
φ([source],[mode],[bytes]) 	Access from or to source with a specified mode and specific bytes per element
φ([source],[mode],[bytes],[element])	Access from or to source with a specified mode and specific bytes per element. The fourth argument gets assigned to the total count of bytes read
=== [source] ===
Source can be one of the following.
Command 	Description
φ 	stdin (standard input)
Φ 	stdout (standard output)
. 	stdrand (standard random)
[string]	string of filename / path
[index] 	index to string of filename / path within memory
=== [mode] ===
Command	Description
Φ 	integer
φ 	float
. 	string or array
=== [math] ===
==== integer and float ====
* most basic math operations are included
* relies on PEMDAS
* when setting a value to a destination and the type of the value is known, the destination is automatically optimized for that
* when setting a value to a destination and the type of the destination is explicitly specified, the value automatically gets casted to the type of the destination 
Table of possible instructions math related.
Command 	Description
[element] 	Get the value of the element
( [math] ) 	Parenthesis around math operation
[element] ^ [element]	Potentiate two elements
[element] * [element]	Multiply two elements
[element] / [element]	Divide two elements
[element] + [element]	Add two elements
[element] - [element]	Subtract two elements
[element] = [math] 	Set element to result of math operation
[element] += [math] 	Add the value of the element to the result of a math operation and set the element to the result
[element] -= [math] 	Subtract the value of the element to the result of a math operation and set the element to the result
[element] *= [math] 	Multiply the value of the element with the result of a math operation and set the element to the result
[element] /= [math] 	Divide the value of the elements by the result of a math operation and set the element to the result
[element] ^= [math] 	Exponentiate the value of the elements with the result of a math operation and set the element to the result
[element]++ 	Increase the value of an element by φ. When this is inlined with = operations, it is executed after the last set occurs (post-increment)
[element]-- 	Decrease the value of an element by φ. When this is inlined with = operations, it is executed after the last set occurs (post-decrement)
(++[element]) 	Increase the value of an element by φ. When this is inlined with = operations, it is executed before the first set occurs (pre-increment). Parenthesis are required to avoid confusion with post-increment.
(--[element]) 	Decrease the value of an element by φ. When this is inlined with = operations, it is executed before the first set occurs (pre-decrement). Parenthesis are required to avoid confusion with post-decrement.
==== strings or arrays ====
Command 	Description
[element] = [math] 	Copy the string of the result of string math into the element (or simply copy strings)
[element] . [element]	Append the right element to the left element. This is smart appending, so if the right element is a string it appends each element within that string
=== [index] ===
* index is an integer value in the range of 0...2^64-1
* the index is accessed in bytes
The table below lists legal instructions. 
Command 	Description
[integer] 	index of integer to within the memory.
[integer],[bytes] 	index of integer to within the memory with the amount of bytes taken into consideration.
[integer],[bytes],[mode] 	index of integer to within the memory with the amount of bytes taken into consideration with a specified mode.
[integer],[bytes],[mode],[element]	Array of size specified by the fourth argument. Starting at index of integer to within the memory with the amount of bytes per element taken into consideration with a specified mode per element.
[element] 	index from integer value of element to within the memory.
[element],[bytes] 	index from integer value of element to within the memory with the amount of bytes taken into consideration.
[element],[bytes],[mode] 	index from integer value of element to within the memory with the amount of bytes taken into consideration with a specified mode.
[element],[bytes],[mode],[element]	Array of size specified by the fourth argument. Starting at index from integer value of element to within the memory with the amount of bytes per element taken into consideration with a specified mode per element.
=== data types ===
==== [literal] ====
The only allowed literal is φ itself, the golden ratio ≈ 1.618033.
Command	Description
φ 	1.618033...
==== [integer] ====
* Because we have one literal we can represent any integer value with basic math at compile time
* The compiler should be intelligent enough to understand when there is an integer or not
* Any integer is always signed. The concept of unsigned integers does not exist in φ
Table of some values below.
Integer 	φ-notation
current index	Φ
0 	φ-φ
1 	φ/φ
2 	(φ+φ)/φ
3 	(φ+φ+φ)/φ
4 	(φ+φ+φ+φ)/φ
48 	(φ+φ+φ+φ+φ+φ)*(φ+φ+φ+φ+φ+φ+φ+φ)/(φ*φ)
256 	((φ+φ)/φ)^((φ+φ+φ+φ+φ+φ+φ+φ)/φ)
==== [float] ====
* If selected through the mode, it will be 8 bytes per value by default, if nothing else is specified (double precision)
* For the order of bytes in memory see the bytes section
List of allowed bytes for the float numbers below.
Bytes	Standard
2 	IEEE754 half precision
4 	IEEE754 sincle precision
8 	IEEE754 double precision
16 	IEEE754 quadruple precision
32 	IEEE754 octuple precision
=== data structures ===
==== [string] ====
* A string is a chain of consecutive integers that gets terminated with a 0
* A . is used to separate between integers
* Standard ASCII or Unicode is used (I/O)
Command 	Description
[integer].[integer].[integer].[integer].0	A compile-time, read only string of four integers
[element].[element].[element].[element].0	A string made up of four individual elements. Treated like integers by default but can also be strings so we're ending up with concenation
==== [array] ====
* An array is a chain of consecutive elements
* A . is used to separate between elements
Command 	Description
[element].[element].[element].[element]	An array of four elements.
==== [variable] ====
* there is one integer variable Φ which is initialized at program start to 1 (technically to φ but because we have to cast to an integer it is rounded down to 1)
* this variable can be in the range of 0...2^64-1
Command 	Description
Φ 	get value of variable
Φ = [math]	adjust the variable to the result of a math operation
Φ++ 	the variable is incremented by 1 (technically it is incremented by φ but because we must cast the value to an integer it is then rounded down to 1)
Φ-Φ 	is the same as an integer 0 value.
Φ/Φ 	is the same as an integer 1 value.
=== [bytes] ===
* bytes can either be an element (forced to integer) or a compile time integer.
* the value represents how many bytes each element occupies
* 0 is defaulted to 1
Representation in memory with different byte sizes
Bytes	index in memory
1 	[n]
2 	[n=LSB][n+1=MSB]
4 	[n=LSB][n+1][n+2][n+3=MSB]
8 	[n=LSB][n+1]...[n+6][n+7=MSB]
=== flow control ===
There is a quite flexible set of flow control instructions.
* φ() indicates flow control (don't confuse with [element])
* | indicates a single check
* I indicates a repetitive check
* . indicates a switch-case
* the idea is that (I) (|) and (.), with a little bit of imagination, can be viewed as enlarged versions of Φ or φ
* basic structure is check if 0 -> path if not 0 -> path if 0
==== if and while ====
Table below lists possible combinations.
Command 	Description
(code if not 0) ) 	if
φ( [element] I (code while not 0) ) 	while
(code if not 0) | (code if 0) ) 	if...else
(code if not 0) I (code while 0) ) 	if...while else
(code if 0) ) 	while...else
φ( [element] I (code while not 0) I (code while 0) )	while...else
==== break and continue ====
Command	Description
φ++ 	break (step out of loop or jump out of scope)
φ-- 	continue (step to beginning of scope)
==== switch-case ====
The structure for the switch-case is similar to the if and while table above.
* first item is an element to be checked on
* to indicate a case, use the .
* a case is a pair of if or whiles from the if and while table above
* use φ++ to break out
* cases are not limited to integers
Example of different switch-cases:
φ(
[element] 				switch(element)
.[element] | (code if equal) φ++	if equal to case element execute code and then break
.[element] |				if equal to case element (execute code "below")
.[element] | (code if equal) φ++	or if equal to case element execute code and then break
.[element] I (code while equal)	φ++	while equal to case element execute code and then break
.[element] I 				while equal to case element (execute code "below")
.[element] | (code while equal)	φ++	or if equal to case element execute code and then break
.(default code)				default code
)
=== [memory] ===
* The largest memory size is 2^64-1 (because this also has to be saved in a variable) making it so that the variable itself takes up 8 bytes of memory
Command 	Description
φ() = [math] 	set memory size in bytes to value of math operation (gets forced to integer). If this is the first instruction, the program should overwrite the default size and start with that specified size instead.
[element] = φ()	get memory size in bytes (empty brackets)
=== random number ===
The instruction φ(.) shall return a (default double precision) random number in the range 0...φ.
=== terminating ===
The program terminates on one of those conditions
* it reaches the end of the program
* the memory size was set to 0
* breaking out of the main scope
=== comments ===
Anything that can't be interpreted as an instruction is considered to be a comment (and who writes comments like those φ-φ... right?).
= Examples =
== Truth-machine ==
φ(φ(φ,Φ)|φ(Φ,Φ)=(φ/φ)φ--|φ(Φ,Φ)=(φ-φ)
== Cat ==
φ(Φ)=φ(φ)
== Golden Ratio ==
This program prints the golden ratio.
φ(Φ)=φ
== Hello, world! ==
This explained program prints "Hello, World!".
Φ(φ/φ)=(φ+φ+φ+φ+φ+φ)^(++Φ)*(φ+φ+φ)/(φ*φ)	set index 1 to 108*phi (ascii 'l')
Φ(φ-φ)=Φ*Φ*Φ*Φ-Φ				set index 0 to 14
φ(Φ(φ-φ)-ΦIΦ(Φ++)=Φ(φ/φ))			set index 2...13 to 108*phi (ascii 'l')
Φ(Φ)=φ-φ					set index 14 to 0 (ascii '\0')
Φ(--Φ)=(Φ-(φ+φ+φ)/φ)*φ				set index 13 to 10*phi (ascii '\n')
Φ(--Φ)=(Φ+Φ+Φ)*φ-φ-φ-φ				set index 12 to 33*phi (ascii '!')
Φ(--Φ)-=Φ*φ-φ-φ-φ				set index 11 to 100*phi (ascii 'd')
Φ=(φ+φ+φ+φ)/φ					set variable to 4
Φ(Φ)+=φ+φ+φ					set index 4 to 111*phi (ascii 'o')
Φ(++Φ)-=(Φ+φ/φ)^((φ+φ)/φ)			set index 5 to 44*phi (ascii ',')
Φ(++Φ)=(Φ-φ/φ)^((φ+φ)/φ)			set index 6 to 32*phi (ascii ' ')
Φ(++Φ)-=Φ*(φ+φ+φ)				set index 7 to 87*phi (ascii 'W')
Φ(φ/φ)-=Φ*φ					set index 1 to 101*phi (ascii 'e')
Φ(++Φ)+=φ+φ+φ					set index 8 to 111*phi (ascii 'o')
Φ(φ-φ)=Φ*(Φ+φ/φ)*φ				set index 0 to 72*phi (ascii 'H')
Φ(++Φ)+=φ+φ+φ+φ+φ+φ				set index 9 to 114*phi (ascii 'r')
Φ+=(φ+φ+φ+φ+φ)/φ				set variable to 14
φ(ΦIΦ(--Φ)/=φ					divide index 0...13 by phi
φ(Φ,.)=Φ(φ-φ)					set stdout to string starting from index 0
This is the same program as above but all whitespace removed.
Φ(φ/φ)=(φ+φ+φ+φ+φ+φ)^(++Φ)*(φ+φ+φ)/(φ*φ)Φ(φ-φ)=Φ*Φ*Φ*Φ-Φφ(Φ(φ-φ)-ΦIΦ(Φ++)=Φ(φ/φ))Φ(Φ)=φ-φΦ(--Φ)=(Φ-(φ+φ+φ)/φ)*φΦ(--Φ)=(Φ+Φ+Φ)*φ-φ-φ-φΦ(--Φ)-=Φ*φ-φ-φ-φΦ=(φ+φ+φ+φ)/φΦ(Φ)+=φ+φ+φΦ(++Φ)-=(Φ+φ/φ)^((φ+φ)/φ)Φ(++Φ)=(Φ-φ/φ)^((φ+φ)/φ)Φ(++Φ)-=Φ*(φ+φ+φ)Φ(φ/φ)-=Φ*φΦ(++Φ)+=φ+φ+φΦ(φ-φ)=Φ*(Φ+φ/φ)*φΦ(++Φ)+=φ+φ+φ+φ+φ+φΦ+=(φ+φ+φ+φ+φ)/φφ(ΦIΦ(--Φ)/=φφ(Φ,.)=Φ(φ-φ)
Category:Languages Category:2021 Category:Unimplemented