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.
This post will cover how to actually determine WHAT the user has typed, instead of just how long it is. It will also include how to interpret what the user enters as a binary number, so that its easier to type.
An Essential part of making it interpret binary numbers is making it double numbers repeatedly.
This actually has a few ways that can be done, so this is one of the first situations where coding style for this problem might differ from person to person. Because of this, I will say more than one way to do it.
The first way to do this it to copy the number twice, and then start from zero and add both of the copies. This is relatively inefficient, and would take
a copy thing, consisting of two bifurcates (which would take a little time)
where the size of the initial number is N, 2N normal bifurcates, 2N reverse bifurcates, and 4N lines relating to the actual loop
assuming each command takes the same amount of time (which is an oversimplification) this would take 9N+C line times. (C is a constant) This might be acceptable, but there is a more efficient and nicer looking way.
The second way is nicer looking, but still not the most effecient. However, when multiplying by a larger number(such as 3, or 4, or even large numbers), this method is part of what would be used.
The second method is essentially copying the number (using a reverse bifurcate and a normal bifurcate), and then adding the number to zero, except instead of each loop increasing the new number by one, it increases it by two. This is shorter, and it looks nicer. It also only takes half as many normal bifurcates. As a result, the number of steps it would take (again assuming each step is the same length) is 8N+C, instead of 9N+C
this one I will write out, but it is still not the best way:
//N is the number initially BIFURCATE [NULL,NULL]2NULL; BIFURCATE [N,N]G; BIFURCATE G[NCOPY,JUNK]; BIFURCATE 2NULL[RESULT,JUNK]; ~ATH(NCOPY){ BIFURCATE NCOPY[JUNK,NCOPY]; BIFURCATE [BLAH,RESULT]RESULT; BIFURCATE [BLAH,RESULT]RESULT; }
ok, so yeah. that takes N, and puts twice N into RESULT, but it is still inefficient.
A more efficient version is to copy the initial number, and add the number to itself. This way you only have to do half the number of reverse BIFURCATE statements. This is much more efficient, taking instead the steps:
a copy thing, consisting of two bifurcates (which would take a little time)
where the size of the initial number is N, N normal bifurcates, N reverse bifurcates, and 2N lines relating to the actual loop
This has 7N+C steps, which is a significant improvement. I think it is the fastest way to double a number in drocta ~ATH.
It is as follows (N is the number)
BIFURCATE [N,N]G; BIFURCATE G[NCOPY,RESULT]; ~ATH(NCOPY){ BIFURCATE NCOPY[JUNK,NCOPY]; BIFURCATE [BLAH,RESULT]RESULT; }
This is shortest and fastest solution I have found. If you find a shorter or faster method, please tell me.
Ok. Now we can double numbers. That is good. That is an important step. But we still haven't gotten user input to be read in any reasonable way.
Hang on, I'm GETTING TO THAT. GEEZ. (I'm kidding, no one has been complaining about my taking so long, other than myself)
Ok, so here goes:
To interpret the binary number input and convert it to a "number", we can follow the following algorithm:
start with zero.(this is before the loop)
If there are any characters left, double the number that is being created.
remove the first character from the remaining characters. If it is "1" or whatever symbol (or alternatively if it is not "0"), add one to the number that is being created. Otherwise, continue onto step 4 without doing anything first.
go back to the start of the loop (step 2)
Ok. thats the algorithm we are going to use. But I STILL haven't explained how to recognize what the next character is. Seriously what is up with that?
What you do is you bifurcate the rest of the input into [the next character,the rest of the input].
Now you have the next character. Then what you do is you reverse bifurcate it with some other object, and then you check whether that object is already dead or not.
But how do you make it so the combination is already dead? How do you get the object for the character before the user has even inputed it?
Answer: You don't. Not in the current version of drocta ~ATH anyway. You will have to tell the user to enter all the characters they will be using ahead of time. Yes this is horrible and stupid. No its not exactly like that in the comic. Its ~ATH what do you expect? :P
that might change in future versions, but I will try to stay backwards compatible with that.
but anyway, back to comparing it:
so you say something along the lines of:
import comparingobject CMP1; othercodehere makeNEQ1besomethingalive BIFURCATE [CMP1,CHAR]EQ1; BIFURCATE [NULL,NULL]2NULL; ~ATH(EQ1){ print yep, they are equal; BIFURCATE 2NULL[EQ1,NEQ1]; } ~ATH(NEQ1){ print nope, they are not equal; BIFURCATE 2NULL[NEQ1,JUNK]; }
in the othercodehere you get the character a head of time, and say BIFURCATE[CMP1,THECHARTHATMATCHESWITHCMP1]D; D.DIE();
That makes it so that it will go through the one section of code if the character is the right one, but something else if it is something else.
Which is what we want.
So to put it all together, and make the thing that interprets the input as a binary number(hold on tight(ok, what, why did I say that), this will be a long one(why am I talking like this?)):
import blah BLAH; print please enter whatever character you will be using for binary zero.; INPUT ZEROCHAR; BIFURCATE ZEROCHAR[ZEROCHAR,JUNK]; import chrcmp CMP0; BIFURCATE [CMP0,ZEROCHAR]D; D.DIE(); print please enter whatever character you will be using for binary one.; INPUT ONECHAR; BIFURCATE ONECHAR[ONECHAR,JUNK]; import chrcmp CMP1; BIFURCATE [CMP1,ONECHAR]D; D.DIE(); BIFURCATE [NULL,NULL]2NULL; BIFURCATE 2NULL[OUTNUM,JUNK]; print please input the binary number you want.(it will be converted to unary); INPUT BINNUM; ~ATH(BINNUM){ BIFURCATE [OUTNUM,OUTNUM]G; BIFURCATE G[NCOPY,OUTNUM]; ~ATH(NCOPY){ BIFURCATE NCOPY[JUNK,NCOPY]; BIFURCATE [BLAH,OUTNUM]OUTNUM; } BIFURCATE BINNUM[CHAR,BINNUM]; BIFURCATE [CMP0,CHAR]NEQ0; ~ATH(NEQ0){ BIFURCATE [BLAH,OUTNUM]OUTNUM; BIFURCATE 2NULL[NEQ0,JUNK]; } } print ok, going to print it out in unary, with each digit on one line. If the number you entered was large you might want to close the program instead of hitting enter.; INPUT JUNK; BIFURCATE [OUTNUM,OUTNUM]GOUTNUM; BIFURCATE GOUTNUM[OUTNUMCOPY,JUNK]; ~ATH(OUTNUMCOPY){ BIFURCATE OUTNUMCOPY[JUNK,OUTNUMCOPY]; print 1; } print Am I a terrible person for writing this?;
Oh gosh. I wish I could indent in tumblr. that is terrible to read. tumblr is a terrible source code editor.
One time someone called me a masochaist for writing this type of stuff.
And then we just have to put that together with the adding thing, and then maybe add a better way of outputting the number. maybe in binary.
HAHAHAHAH
ok, yeah, I'm going to put it together in the next post, not this one, because I have to homework now.(using the noun homework as a verb was intentional)
yeah. putting it together in the next post.
As always, if something was confusing, please ask for clarification.
Heyho, I now red alot of your sources and i started to understand your interpretation of ~ATH. You do alot of things with the bifurcate command.. I actually thought that bifrucate JUST splits the programm in different colors like here : "bifurcate THIS[THIS(red), THIS(blue)]; " I think that you can actually split your script into N colors while N > 0. like this: bifrucate THIS[THIS(COLOR(0),THIS(COLOR(1),THIS(COLOR(2),THIS(COLOR(3),THIS(COLOR(4),THIS(COLOR(5),THIS(COLOR(6)] and so on.
Yes. I do use BIFURCATE often.
Personally, I doubt that one could say
BIFURCATE A[D,B,C]; (for some names and colors for a b c and d),
because of the "Bi" part of the word "bifurcate", meaning two. (or in some cases, "both")
Further, I would defend my use of it to BIFURCATE things other than THIS with http://mspaintadventures.com/?viewmap=6 which, for the start of act 5, says
BIFURCATE ACT_5[red(ACT_1), blue(ACT_2)];
which seems to indicate that things other than THIS can be BIFURCATED.
To split something into more than 2 parts, I would just bifurcate it multiple times. *
I don't know what the etiquette is for whether I should click publish or answer privately, so I am going to pick one and hope for the best.
I am still here, and I am wondering what my update schedule for this tutorial should be.
Its been a week or two since I last posted part of the tutorial, so I feel like I probably should have posted during that time, but I haven't.
I will probably post one today.
Do you have any suggestions for what type of update schedule I should keep on this tutorial?
PRINT2 prints a string object as a string. If you give it something that is not a string object it will probably crash, or output the empty string.
Now, to import user defined functions use
importf filename as FUNCTIONNAME;
Why didn't I put this up earlier?
because I have other projects and because sometimes I am busy/lazy.
OK!
So to make a function to import, you pretty much make a ~ATH file like normal, except the object passed into the function is put into the variable ARGS, and when you want to pass the output object of the function out, you have it as an argument to the DIE method.
It can either be when saying THIS.DIE(RETURNOBJ); or ANYOTHERVARIABLE.DIE(RETURNOBJ);
The object your killing doesn't have to be the one tied to the life of the function or anything.
Oh I should clarify, the THIS variable/object will refer to the current function, not the file that called it.
It CAN be returned, and will be dead when you exit the function.
PROGRESS!
FUNCTIONS WORK.
LESS SPAGHETTI CODE.
although this starts to make me wonder if maybe this strays too far from what ~ATH is like in comic,
but w/e.
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 am planning two features to add.
one us user defined functions.
the second is, uh, it would let you make an object that would have itself as one of its components or one of the component of one of its components etc.?
the third one I am not sure if I think it is dumb yet, but I was thinking maybe functions being objects that you can bifurcate together to make functions.
which would allow for macros kind of?
which of these three features are good ideas, (as in, for each, it is a good idea)?
So recently I started kind of working on this again for a bit. I have fixed some bugs with the parser that I haven't pushed yet. I am also writing an improved interpreter that will use the parser instead of the hacky thing that just goes through strings.
However, for the time being, even after I release this version, I would recommend maybe using the older version for a while if anyone is using it, because this version is probably even more buggy.
However, you know how a few posts ago (but more than a year ago (wow) ) I posted that post where I said that I didn't think bifurcate can be used to split values into more than 2 values?
Well I still kind of think that, but on the map page for homestuck on act 6, it says split Act_6[Act_1,Act_2,Act_3,<etc>];
So this is something I intend to implement, and something I am implementing.
And like I said before I would like it to be done with repeated bifurcation, as a sort of syntactic sugar.
And I am thinking I want it to be like
[a,b,c] means the same thing as [a,[b,c]]
so split Z[A,B,C];
would be the same as
BIFURCATE Z[A,BCTEMP]; BIFURCATE BCTEMP[B,C];
and that split [A,B,C]Z;
would be the same as
BIFURCATE [B,C]BCTEMP; BIFURCATE [A,BCTEMP]Z;
But the way the splits would be done could also be backwards
so [a,b,c] could be the same as [[a,b],c]
I'm pretty sure I prefer the first way, but the second way is actually easier to implement.
or at least cleaner looking to implement.
Why doesn't my code look clean ever?
Anyway, my reason for this post is this:
Does anyone have any opinions about how split is implemented?
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!
I made a parser for ~ATH in addition to the interpreter. I might make the interpreter use the parser at some point in the future, or I might not. If I made the interpreter use the parser, the code for the interpreter would probably be a little cleaner, and possibly a little faster.
The parser is available from my github.
To use it, call tokenize on the text, and then read_all_from on the result of tokenize.
The output will be a list of lists
https://github.com/drocta/TILDE-ATH-Parser
(haven't updated lately because of other unrelated projects, and also other reasons that aren't necessary to describe)
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