News and tutorials on drocta ~ATH by drocta. interpreter here A brief summary of how to write code in the language (but also see the table of contents)
38 posts
I had written the code for user input a while ago, but apparently it didn't get put on github. And then my local copy got deleted. But I rewrote it today, and I fixed a bug with reverse bifurcation. So it should work now. And I have confirmed that it did indeed get put on github, so I don't need to worry about this happening again.
Most programs people use have some form of user input. A calculator isn't much use if it always uses the same numbers after all!
~ATH of course accepts user input and output as shown in the file Roxy sent Jane.
Also I just found out you can put more than one read more line in one post.
The input command has the syntax:
INPUT VARNAME;
What this does is when program execution meets this line, the program pauses execution, allowing the user to input text. When the user hits enter, program execution will continue and the variable VARNAME will be made to point to an object corresponding to the text the user entered.
This object is such that the left half is the object that corresponds to the first character. If there is no character after that, the right half will be the NULL object. Otherwise the right half will be the object corresponding to the input without the first character. If they hit enter without inputting any characters the object will just be the NULL object.
Now that we have that all explained, we can start to make programs that actually take user input!
As you might have guessed from the title, the thing we will be making is a very basic calculator. All it does is add two numbers, like in the last example.
But in this, it will get the numbers from the user!
One simple way to do this is to use the length of the input text as the number: The way we define what we call numbers just so happens (heh) to be such that if we interpret the object for the input string as a number, the number will be the same as the length of the input!
This isn't the greatest solution, but it is easier than other methods. We will use this method first and then move on to other methods that are harder to write, but will be nicer when using the end program.
HERE WE GO:
ok, so like I said, much of it is pretty much the same as that previous program, so we might as well just include said here:
SOME CODE TO GET A AND B HERE import bluh BLAH; BIFURCATE [BLAH,A]ATEMP; BIFURCATE [BLAH,B]BTEMP; BIFURCATE ATEMP[JUNK,ATEMP]; BIFURCATE BTEMP[JUNK,BTEMP]; BIFURCATE [BLAH,NULL]C; BIFURCATE C[JUNK,C]; ~ATH(ATEMP){ BIFURCATE ATEMP[JUNK,ATEMP]; BIFURCATE [BLAH,C]C; } ~ATH(BTEMP){ BIFURCATE BTEMP[JUNK,BTEMP]; BIFURCATE [BLAH,C]C; } BIFURCATE [BLAH,C]CTEMP; BIFURCATE CTEMP[JUNK,CTEMP]; ~ATH(CTEMP){ BIFURCATE CTEMP[JUNK,CTEMP]; print some text; } print DONE!;
so pretty much what we need to do it put the code to get A and B where that goes(at the beginning), as well as stuff to tell the user how to print stuff.
Like I said, the objects from the input commands can be interpreted as numbers.
so this becomes:
print INPUT SOMETHING WITH THE NUMBER OF CHARACTERS AS THE FIRST NUMBER YOU WANT TO ADD; INPUT A; print INPUT SOMETHING WITH THE NUMBER OF CHARACTERS AS THE SECOND NUMBER YOU WANT TO ADD; IMPORT B; import bluh BLAH; BIFURCATE [BLAH,A]ATEMP; BIFURCATE [BLAH,B]BTEMP; BIFURCATE ATEMP[JUNK,ATEMP]; BIFURCATE BTEMP[JUNK,BTEMP]; BIFURCATE [BLAH,NULL]C; BIFURCATE C[JUNK,C]; ~ATH(ATEMP){ BIFURCATE ATEMP[JUNK,ATEMP]; BIFURCATE [BLAH,C]C; } ~ATH(BTEMP){ BIFURCATE BTEMP[JUNK,BTEMP]; BIFURCATE [BLAH,C]C; } BIFURCATE [BLAH,C]CTEMP; BIFURCATE CTEMP[JUNK,CTEMP]; ~ATH(CTEMP){ BIFURCATE CTEMP[JUNK,CTEMP]; print some text; } print DONE!;
So yeah. That should work. I still need to test this, but I am pretty dang sure that this works.(have to go do homework now) In the next post I will explain how to make it so that the user can type in the number as an actual number!
In drocta ~ATH, the control flow (what part of the program is run when) is almost entirely determined by ~ATH loops.
The only case where it isn't is when the object initially pointed to by THIS dies. That ends the program immediately.
This post will show in more detail the basics of its usage.(also introduces the variable NULL)
Is there anything in this post that needs to be clarified?
In a program, you might want something to only happen if something else is true, or you might want it to happen provided that something had not happened.
In many programming languages you would use a command called if.
drocta ~ATH does not have an if statement.
Instead, you create a loop on an object, and inside the loop kill the object.
A little morbid, but isn't ~ATH always?
for example:
SOMECODEHERE ~ATH(SOMEVAR){ SOMEVAR.DIE(); SOMEOTHERSTUFF } SOMEOTHERSTUFF
However, this isn't the only way. There is another way that is likely preferable in most situations. I just thought this way was the most obvious, and would be an easy way to explain the other method, which is quite similar.
The loop doesn't exactly wait for the object to die, but rather repeats so long as the variable points to an object that is alive. The variable can be made to point to an object that is not alive, either by make the object it points to DIE(), or by making it so it points to a different object that is ALREADY DEAD.
(How can you expect to kill it, when it is ALREADY DEAD?!? haha)
So if the object you wanted the part of the script to run if it was alive was important, and you didn't want to kill it, you could just do this:
BIFURCATE [IMPORTANTOBJECTVAR,IMPORTANTOBJECTVAR]BLAH; BIFURCATE BLAH[V,V]; ~ATH(V){ BIFURCATE [V,NULL]V; BIFURCATE V[JUNK,V]; OTHER CODE TO ONLY EXECUTE IF IMPORTHATOBJECT IS ALIVE }
Thats nice to be able to do, isn't it.
In fact, it leads nicely into how to make loops that go around a fixed number of times.
suppose if you had
BIFURCATE [BLAH,NULL]V; ~ATH(V){ BIFURCATE V[BLAH,V]; DO OTHER STUFF, POSSIBLY WITH BLAH } MORE STUFF
V would initially be alive, so it would go into the loop, but then V would be made to point to the NULL object, which is dead, so it wouldn't loop the second time.(it would skip to after the loop
that would do the stuff in the loop once.
now what if you wanted to do it twice?
Just make it so it has to bifurcate the thing twice before moving on! Like so:
BIFURCATE [BLAH,NULL]V; BIFURCATE [BLAH,V]V; ~ATH(V){ BIFURCATE V[BLAH,V]; DO OTHER STUFF, POSSIBLY WITH BLAH } MORE STUFF
this way it will go through the loop, pop off the one side of V, doing the other stuff in the loop. V will still point to something alive after this, so it will do it again, but this time, when it pops off one side of V, the result will be the NULL object, so it will stop.
Thats a loop that goes around twice!
This can be extended to as many number of repetitions as follows:
BIFURCATE [BLAH,NULL]V; BIFURCATE [BLAH,V]V; BIFURCATE [BLAH,V]V; BIFURCATE [BLAH,V]V; ETCETERA BIFURCATE [BLAH,V]V; ~ATH(V){ BIFURCATE V[BLAH,V]; DO OTHER STUFF, POSSIBLY WITH BLAH } MORE STUFF
where the loop will go around however many blahs there are attached to the NULL, because it will keep popping the BLAHs of until it reaches NULL.
The variable V is being used to store how many more loops need to be executed, Which is a number.
V is being used to store a number.
You might be thinking something along the lines of
"Well this is all very nice, but that seems to only allow for loops that loop a predetermined amount of times."
NOT SO!
You can have another loop that makes a variable point to a number, which would then be in another loop! For example, the following will add two numbers in A and B, store the result in C, copy that result to CTEMP, and then print "some text" the ammount of times in CTEMP!
SOME CODE TO GET A AND B HERE import bluh BLAH; BIFURCATE [BLAH,A]ATEMP; BIFURCATE [BLAH,B]BTEMP; BIFURCATE ATEMP[JUNK,ATEMP]; BIFURCATE BTEMP[JUNK,BTEMP]; BIFURCATE [BLAH,NULL]C; BIFURCATE C[JUNK,C]; ~ATH(ATEMP){ BIFURCATE ATEMP[JUNK,ATEMP]; BIFURCATE [BLAH,C]C; } ~ATH(BTEMP){ BIFURCATE BTEMP[JUNK,BTEMP]; BIFURCATE [BLAH,C]C; } BIFURCATE [BLAH,C]CTEMP; BIFURCATE CTEMP[JUNK,CTEMP]; ~ATH(CTEMP){ BIFURCATE CTEMP[JUNK,CTEMP]; print some text; } print DONE!;
YAY! We just added two numbers together! In similar ways, we can also subtract, multiply, divide, etcetera!
if some of this was unclear I would appreciate requests for what needs to be clarified.
Is there anything in this post that needs clarification?
I have completed the syntax explanation post, and I think it is fairly clear now.
If you find any part of the post to be unclear, and that it requires further explanation, please say so so that I can improve it.
Now that that post is in an acceptable form, We can get on to writing our first few ~ATH programs.
print Hello, World.; THIS.DIE();
That wasn't so hard, was it?
I feel I should note that the syntax of the print command is not entirely finalized, it might change sometime later.
EXPLANATION:
The first line of the program says to output the text "Hello, World."
The 2nd line of the program says to end the program. This is because the variable THIS initially points to a object that is only alive when the program is running. If the object is ever not alive, the program stops.
oh gosh why is this a bullet-ed list I am not good with tumblr
To run a drocta ~ATH program, you need the interpreter (available from the github), and python 2.7 (the interpreter can be easily modified to run with python 3, but it is written to work in 2.7)
Open interp_2.py with python, and when the program comes up, type in the filename of the ~ATH program, and hit enter, this will run the ~ATH program.
With this example, it should output the text
Hello, World.
Now, of course, this is a relatively simple program, but at least its something.
Depending on how you are running the interpreter, the program might close immediately after outputting the text.
That might not be what we want.
To make the program not close until we specifically tell it to, we use the following:
print Hello, World.; ~ATH(THIS){ } THIS.DIE();
EXPLANATION:
The first line is the same as in the first program. It outputs "Hello, World."
The second line is different, this says to start a loop, which will continue until the object pointed to by the variable THIS is dead.
The third line says to go back to the corresponding ~ATH statement.
The fourth line is never executed, because the loop above it will continue until the object pointed to by THIS dies, and if that object dies the program ends. If it were to be executed it would make the object pointed to by THIS die, and the program would end as a result.
This program should be the same, except that it will keep running until you close it manually.
Now you have hello world written in two different ways!
~ATH is a programming language. A programming language is a language that can be used to write programs in, that can afterwards be run. ~ATH appears in Homestuck, and drocta ~ATH is my attempt at making it a real thing.
drocta ~ATH is limited to what is physically possible of course, because it actually exists. It is also limited to fit well with the comic, and how much of it I have created so far.
As such, so far all the programs that can be written in drocta ~ATH are text only, do not yet accept input (input in progress), and tend to be stupidly long.
It is however capable of computing anything a computer can given enough time and memory.
~ATH is based on objects, and the lives thereof.
For example, in homestuck, there are programs that relate things to the lifespan of a universe, or a person, etc.
Of course, in order to make an interpreter possible, we have to limit ourselves to virtual objects. Ones that do not actually exist.
References to these objects are stored in things called variables. You probably know what these are already, but if you don't, think of a variable as a box that can have a thing in it. Each box has a name. You can say "do something with whatever is in the box called "apple".
In ~ATH, every object is either "alive" or "dead". Note that it is the object that is alive or dead, not the variable that refers to the object.
Now onto the actual syntax!:
Currently(as of build 7), drocta ~ATH has 5 different commands: import, ~ATH(){}, .DIE();, print, and BIFURCATE.
First we will go over the import statement. The import statement has the purpose of creating a new variable and a new object. Unlike other operations that can create a new object, the object created by import is initially unrelated to all of the other objects.
The syntax of the import command is:
import anything other than semicolons here VARIABLENAME;
The things between import and the last space before the semicolon are ignored.
In future versions, the import statement might also do additional things, such as using things from other files. But for now it just initializes variables.
EXAMPLES:
If you wanted to make a new variable called BANANA, and you wanted the reader to know that BANANA is a fruit, you would say:
import FRUIT BANANA;
or you could say
import YELLOW FRUIT BANANA;
The things that go before the variable name don't actually matter, you can say
import ghsdgh hgsdkhg hgksdhg hgskdjg BANANA;
if you wanted.
Now for the next command: The eponymous ~ATH loop!
The syntax of it is as follows:
~ATH(VARNAME){ Some other code goes here }
What this does, is each time the code execution gets to the ~, it checks what the variable in the parentheses is, and then checks the object the variable points to. If the object is alive, it continues. If the object is dead, it skips to after the }. When the Code execution reaches the }, (that is, if it did not skip to after it), it will jump back to the corresponding ~. Code execution will keep going around in this loop until the object pointed to by the variable is not alive. In later versions, there may be an additional requirement that the } be followed by EXECUTE(code here); Where code here can be replaced with ~ATH code, NULL, or possibly a file name. But currently, this is not the case. Now onto the command BIFURCATE!: Bufurcate actually has 2 forms, the standard bifurcate, And the reverse bifurcate. The first of the two has syntax as follows:
BIFURCATE VARNAME1[VARNAME2,VARNAME3];
What this does, is it takes the object pointed to by the first variable, and determines two objects, which are stored in the other two variables. The two objects determined will always be the same for a particular object. If you for example say:
BIFURCATE V1[V2,V3]; V2.DIE(); BIFURCATE V1[V4,V5];
then V4 and V2 will point to the same object, which will be dead.
The other form of the BIFURCATE command has syntax as follows:
BIFURCATE [VAR1,VAR2]VAR3;
This is pretty much the inverse operation. That is, it undoes the other one. If you say for example:
BIFURCATE A[B,C]; BIFURCATE [B,C]D;
then A and D will point to the same object. To be clear, undoing the other is not the only time you can use it. It will take any two objects, and determine an object from those two. If there is already an object for the combination of those two, then that object is the resultant object. If none has been created yet (and the two arent split from something in that order), it will create a new object, which it will put in VAR3.
To be clear, if you say:
BIFURCATE A[B,C]; BIFURCATE [C,B]D;
A and D will NOT point to the same object, unless you create A such that B and C are the same. That is, if you say:
BIFURCATE [Y,Y]A; BIFURCATE A[B,C]; BIFURCATE [C,B]D;
A and D WILL point to the same object, and B and C will both point to the same object as Y (and as each other).
The Final command is print.
print is pretty simple, but its syntax might change somewhat.
Currently the syntax is:
print the text you want to output;
Note the semicolon. the semicolon is important.
So hello world would be
print Hello, World.;
SYNTAX EXPLANATION COMPLETE! PLEASE SUGGEST CLARIFICATIONS IF NECESSARY.
MESSAGE END.
Fixed the bug. The problem was that it was seeing
\n}\nD.DIE();
and it was checking if the text up to the next semicolon ended with .DIE() and if it did, using the stuff before the . as the variable name. When it should have been seeing the } and jumping back.
Also there may have been a problem with the {} matching. If so, that was fixed too. It was not the last part to be fixed.
BUT ANYWAY: The bug is fixed now.
runs in python 2.7
If you have a different version of python, and it is incompatible, please tell me. If a sufficient number of people want it in a different python version I might make a version of it for multiple python versions.
Ok, if you tried running a script with the interpreter, it might not have run properly. The part of the code that handles what part of the code is executed next is buggy. It is in the process of being fixed. Also, if python gives you a syntax error, it is probably because you are using a different version of python. Change raw_input to input And change print stuff to print(stuff) I will post an introduction to the syntax soon.
If its not obvious, this blog will teach techniques in a version of ~ATH Specifically, drocta ~ATH. And yes, I'm serious. I believe that I probably am the author of the longest ( possibly up to third longest) ~ATH program. Specifically, bubble sort. Further, I believe I am the author of the first ~ATH interpreter. (I am the drocta of drocta ~ATH) Link here: http://www.mspaforums.com/showthread.php?50314-ATH-interpreter This blog is intended to serve as a tutorial on writing things in drocta ~ATH. First I will go over the syntax. Then how to make conditional like things. Then how to make finite loops. Then perhaps storing "numbers". Then copying "numbers" Then comparing "numbers" Then lists In such a way I intend to work our way up to you understanding how to write bubble sort in drocta ~ATH. After that, we might even implement brainf*** in it. Or a universal Turing machine. Of course, when I say "numbers", the quotes are there for a reason. Numbers are not built into drocta ~ATH. One has to build them. Now how do I tag things...? Ah, that's how. In case it wasn't clear, the interpreter for drocta ~ATH does not attempt the impossible. It cannot trigger the apocalypse. It's just a python script that interprets ~ATH scripts. Don't worry if you don't already know how to program. I intend to make the posts fairly accessible.