Photon

From Esolang
Jump to: navigation, search

Photon

Photon is an esolang where each command has the same structure. They take the form of two arguments passed to a function.

Intro

Arguments are made of 2 characters: a symbol and a digit. If the symbol is a #, the digit is interpreted as a literal value, ie. #9 would evaluate to 9. If it is a :, the digit is interpreted as a variable, ie. :9 would give the value of the variable 9. There are two special values:

- is a null value, used for functions taking fewer than two arguments.
$ is the result of the last function returning a value.

Functions are always 1 character, never a letter or number. All lines have the following format: [arg1,arg2>func] This format must be kept EXACTLY. Any lines not following it will not run, and can be used for comments. No spaces are allowed. Because of this, in an ideal Photon program, there will be no letters.

Command List

Character Command
+ Add the two arguments.
- Subtract the two arguments, replacing negatives with 0.
* Multiply the two arguments.
/ Divide and floor the two arguments.
_ Print the numerical value of the first argument. Ignore the second.
. Reset the variables. All user defined variables are deleted, and :$ is set to 0.
@ Print the ASCII value of the first argument.
~ Print a newline.
= Set the variable named the first argument to the second.
 ? Set the variable of the first argument to the ASCII value of an input character if it is not a digit, to it if it is.
^ Go to the line of the first argument. (0 = first line)
{ If the first argument is not 0, go to the line of the second argument.

Examples

Hello World

[#9,#0>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#2,:$>+]
[#7,:$>+]
[:$,:->@]
[:$,#3>-]
[:$,:->@]
[#7,:$>+]
[:$,:->@]
[:$,:->@]
[#3,:$>+]
[:$,:->@]
[:$,:$>-]
[#8,:$>+]
[#8,:$>+]
[#8,:$>+]
[#8,:$>+]
[:$,:->@]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#1,:$>+]
[:$,:->@]
[:$,#8>-]
[:$,:->@]
[#3,:$>+]
[:$,:->@]
[:$,#6>-]
[:$,:->@]
[:$,#8>-]
[:$,:->@]
[:-,:->~]

99 Bottles

[:1,#0>=]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[#9,:$>+]
[:1,:$>=]
[:2,#0>=]
[#8,#8>+]
[:2,:$>=]
[:1,:->_]
[:3,#0>=]
[#8,#4>*]
[:3,:$>=]
[:3,:->@]
[:3,:3>+]
[:$,#2>+]
[:3,:$>=]
[:3,:->@]
[#9,:3>+]
[#4,:$>+]
[:3,:$>=]
[:3,:->@]
[#5,:$>+]
[:3,:$>=]
[:3,:->@]
[:3,:$>=]
[:3,:->@]
[:$,#8>-]
[:3,:$>=]
[:3,:->@]
[:$,#7>-]
[:3,:$>=]
[:3,:->@]
[:$,#9>+]
[:$,#5>+]
[:3,:$>=]
[:3,:->@]
[#8,#4>*]
[:3,:$>=]
[:3,:->@]
[:3,:3>+]
[:$,#1>+]
[:$,#9>+]
[:$,#5>+]
[:3,:$>=]
[:3,:->@]
[:$,#9>-]
[:3,:$>=]
[:3,:->@]
[#8,#4>*]
[:3,:$>=]
[:3,:->@]
[:3,:3>+]
[:$,#2>+]
[:3,:$>=]
[:3,:->@]
[:$,#3>+]
[:3,:$>=]
[:3,:->@]
[:3,:->@]
[:$,#9>+]
[:$,#4>+]
[:3,:$>=]
[:3,:->@]
[:-,:->~]
[:1,#1>-]
[:1,:$>=]
[:1,:2>{]

Take and Square User Input

[:1,#0>=]
[:1,:->?]
[:1,:1>*]
[:1,:$>=]
[:1,:->_]
[:-,:->~]
[:-,:->.]

More examples are included in the source here.
Category:Languages