12
1
The popular webcomic Homestuck makes use of a programming language called ~ATH
to destroy universes. While this code golf challenge is not to write a program to annihilate our existence, we will be destroying some more tame (albeit less interesting) entities: variables.
~ATH
(pronounced "til death," notice how ~ath
is "tilde ath") works by creating a variable called THIS
, executing a command with EXECUTE
, and finishing the program with THIS.DIE()
. A wiki page for the language's use in Homestuck can be found here. The goal of this challenge will be to create a ~ATH
interpreter.
For the sake of the challenge, I'm going to create some details of ~ATH
that don't really exist but make it (somewhat) useful.
- The language will only work with integers, which are declared with
import <variable name>;
. The variable will automatically be set to a value of 0. Only one variable at a time can be imported. - A variable
x
can be copied by writingbifurcate x[y,z];
, which will delete the variablex
and replace it with identical variablesy
andz
. Note that it cannot create a variable with the same name as the one deleted. Essentially, a variable is renamed, then a copy of the variable with a different name is created. This seems like a stupid feature, but stupidity is very deeply ingrained in Homestuck. - The syntax for writing a program that executes code on
x
is~ATH(x){EXECUTE(<code>)}
. If you want to execute code on two variables simultaneously, the code becomes nested, like this:~ATH(x){~ATH(y){EXECUTE(<code>)}}
. All commands in<code>
will be executed on bothx
andy
. - Now let's move onto commands.
+
increments relevant variable(s) by 1 and-
decrements them by 1. And... that's it. - The final feature of
~ATH
is that it kills whatever it works with. Variables are printed in the format<name>=<value>
(followed by a newline) at the command[<name>].DIE();
. Afterwards, the program prints the wordDIE <name>
and a newline a number of times equal to the absolute value of the value of the variable. When variables are killed simultaneously with[<name1>,<name2>].DIE();
(you can have as many variables killed as you want, so long as they exist), theDIE()
command is executed on the variables sequentially.
Example programs
Program 1:
import sollux; //calls variable "sollux"
import eridan; //calls variable "eridan"
~ATH(sollux){EXECUTE(--)} //sets the value of "sollux" to -2
~ATH(eridan){EXECUTE(+++++)} //sets the value of "eridan" to 5
[sollux].DIE(); //kills "sollux", prints "DIE sollux" twice
~ATH(eridan){EXECUTE(+)} //sets the value of "eridan" to 6
[eridan].DIE(); //kills "eridan", prints "DIE eridan" 6 times
Output:
sollux=-2
DIE sollux
DIE sollux
eridan=6
DIE eridan
DIE eridan
DIE eridan
DIE eridan
DIE eridan
DIE eridan
Program 2:
import THIS; //calls variable "THIS"
~ATH(THIS){EXECUTE(++++)} //sets the value of "THIS" to 4
bifurcate THIS[THIS1,THIS2]; //deletes "THIS", creates variables "THIS1" and "THIS2" both equal to 4
~ATH(THIS1){EXECUTE(++)} //sets the value of "THIS1" to 6
[THIS1,THIS2].DIE(); //kills "THIS1" and "THIS2", prints "DIE THIS1" 6 times then "DIE THIS2" 4 times
import THAT; //calls variable "THAT"
bifurcate THAT[THESE,THOSE]; //deletes "THAT", creates variables "THESE" and "THOSE"
~ATH(THESE){~ATH(THOSE){EXECUTE(+++)}EXECUTE(++)} //sets the value of "THESE" and "THOSE" to 3, then sets the value of "THESE" to 5
[THESE,THOSE].DIE(); //kills "THESE" and "THOSE", prints "DIE THESE" 5 times then "DIE THOSE" 3 times
Output:
THIS1=6
DIE THIS1
DIE THIS1
DIE THIS1
DIE THIS1
DIE THIS1
DIE THIS1
THIS2=4
DIE THIS2
DIE THIS2
DIE THIS2
DIE THIS2
THESE=5
DIE THESE
DIE THESE
DIE THESE
DIE THESE
DIE THESE
THOSE=3
DIE THOSE
DIE THOSE
DIE THOSE
This is code golf, so standard rules apply. Shortest code in bytes wins.
2Til death. I see what you did there. – Digital Trauma – 2015-11-22T03:03:17.503
3@DigitalTrauma I gotta pass the credit to Andrew Hussie (the guy who writes Homestuck) for coming up with the name. – Arcturus – 2015-11-22T03:11:28.900
@ the downvoters, would you mind sharing what you think could be improved? – Arcturus – 2015-11-22T04:30:38.850
Should the interpreter be pedantic about semicolons on line-endings? or can it just ignore their existence or lack thereof? – cat – 2015-11-22T16:09:29.993
Also, does it have to function like a REPL or can we read from a file? – cat – 2015-11-22T16:10:02.540
Is case sensitivity important everywhere or just in output? – cat – 2015-11-22T16:14:36.667
1@sysreq
~ATH
uses semicolons as line-endings for theimport
,bifurcate
, andDIE
commands. Both REPL and files are fine. Case sensitivity is required in both the input and the output (I'm trying to match the actual~ATH
as much as possible). – Arcturus – 2015-11-22T16:14:39.037Can we assume that EXECUTE statements like
{EXECUTE(+-++--+--)}
are not valid syntax and should be ignored? – cat – 2015-11-22T18:15:23.013@sysreq Without
~ATH(<name>)
, those statements are not valid syntax. However, with~ATH(<name>)
, that statement would decrement the variable by 1. – Arcturus – 2015-11-22T19:51:19.883the last line in program 2 doesn't end in a semicolon, but it should. I just spent 15 minutes refactoring my parser to figure out why it was recording values incorrectly, but it was a missing semicolon. I never thought I'd fall for one of those :-( – cat – 2015-11-22T23:07:24.563
Also, the wiki's description of the language is wildly different (from a bare syntax perspective) from what's described here; I assume it's o.k. if I use strictly your spec? – cat – 2015-11-22T23:11:00.807
1@sysreq I had to change a few things so the language would actually do something in real life, pecs I described are fine. – Arcturus – 2015-11-23T01:45:24.657
2I'm honestly surprised this question hasn't gotten more responses, and even more surprised there's no horde of Perl wizards armed with regexy wands of magic – cat – 2015-11-23T01:48:09.773
1Maybe it's because the final product is rather large or that after all, this is an interpreter for a fake language that doesn't exist in the human world. – Arcturus – 2015-11-23T01:50:06.047
1That means I maintain the only interpreter for a fictional language from a fictional universe with a large nerd fanbase. Makes me want to improve it. – cat – 2015-11-23T13:08:58.910