CodeWalrus

Development => Calculators => Calc Projects, Programming & Tutorials => Topic started by: JWinslow23 on January 18, 2016, 11:25:27 PM

Title: Beatnik Esolang Interpreter
Post by: JWinslow23 on January 18, 2016, 11:25:27 PM
Are you tired of regular old programming languages? Do you ever wish there was something less code-y to code in? Haven't you ever wanted to talk like a beatnik?

Well, then Beatnik is the esolang for you!

For those who don't know what an esolang (or "esoteric programming language") is, it is "a computer programming language designed to experiment with weird ideas, to be hard to program in, or as a joke, rather than for practical use."

Beatnik is one example of an esolang, created by Cliff L. Biffle (http://cliffle.com/) sometime near 2001 (the exact year is unknown). It's especially nice in my opinion, because most of you already know how to write valid Beatnik code, and a reference to its full vocabulary can be found at any toy store. Allow me to explain...

How it works: Beatnik code takes the form of English words. For example, "Hello, aunts! Around, around, swim!" is a valid Beatnik program, despite not making much sense. (What that does, if you're curious, is it reads a character from the user, adds 7 to it [i.e. A -> H], and prints it out.) The function of a word (for example, "aunts" or "swim") is determined by the score one would receive by playing that word in English Scrabble (for example, "Hello" is 8 points, which would turn into INPUT, etc).

Beatnik is a stack based language. For those unfamiliar, a stack is very simple. You can put things on top, or "push", and take things off (in order from top to bottom), or "pop", and that's it. So, if you push 2 and 3, and do an "add" instruction, 2 and 3 are "popped", added into 5, and then the result it "pushed".

The numbers Beatnik deals with range from 0 to 255. The values wrap around, i.e. 0-1=255, and 255+1=0.

Full instruction list, as from the official specification:

By now, you may be wondering, why is it called Beatnik? Well, you're about to find out. Here is the source for a program that simply prints all printable ASCII characters.
Ho humbuzz, Dionysus. | orgasm if I feel altruistic & alone...

Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch?! Ha!

Monarchies spoil; language intermediates everyone!

See?

Now, for my interpreter. I made it in TI-BASIC as a little fun project, using this interpreter (http://web.archive.org/web/20110723090115/http://www.club.cc.cmu.edu/~rjmccall/beatnik.html) for reference. Some information about it:


Screenie of the Beatnik interpreter running "Hello, aunts! Around, around, swim!":
(http://i.imgur.com/zEEeDQT.gif)

Other example programs:

Truth machine (made by me):
Truth beyond frontiers remains, but amazingly, falsities stay constant, existing greater.

Print "I LOVE YOU" (made by me, in a way that flows like a story):
He arrived.

He arrived at my door extremely late one day.

If you only did uninteresting, idle things in your life, always acting as if nothing he does will change your opinion ... can go well.

But one awful dilemma I face, is that growing emotion ruins my serious, careful way of thinking. If a love flame is forced and futile, why bother kindling another one?

Yet, you think, it might not be a bad idea. Relationships always work out, and this can be an escape from a tense, complex life. Unmarried at home, lost in a loud, irregular reality ... maybe sometime, just maybe, it's time I found the one.

If he's a guy who is faithful, kind, and will be mine joyously to the end, I will prove to him I shall cherish and treasure him just as much. But how do I say it? I can't place the words...

"You absolutely need to know", I say, nervously, "that I...I...I..."


The download for the interpreter is attached to this post. Go ahead, and tell me what you think!
Title: Re: Beatnik Esolang Interpreter
Post by: kegwaan on January 19, 2016, 12:11:55 AM
So the way that this works, could you just types in anything and have the program run? Or could you end up with an error? or would anything interesting happen? It would be interesting to see stuff like full books inputted and then have an output.
Title: Re: Beatnik Esolang Interpreter
Post by: JWinslow23 on January 19, 2016, 01:56:17 AM
You are able to input anything, and if the instructions don't error with something illegal (i.e. popping a value off an empty stack), then SOMETHING is gonna happen. What happens, though, depends on the words, and likely nothing of use or coherence will happen.

Don't worry, though, I'm not stupid. I have implemented error checking for such situations, and it exits with an error message such as "No immediate for PUSH at 8" or "Jump past beginning of program in JNZF at 19" if anything illegal happens during execution.

What you have to do to do anything useful is write the code yourself, then turn that into words.
Title: Re: Beatnik Esolang Interpreter
Post by: kegwaan on January 19, 2016, 12:40:15 PM
I see now. But I bet you could use this language to embed secret messages almost anywhere. I tried making a program in Beatnik that displays "CODEWALRUS" but it's taking a long time to get right.
Title: Re: Beatnik Esolang Interpreter
Post by: JWinslow23 on January 19, 2016, 12:57:47 PM
Heh, if you could find the right words to use, you could put secret messages in places with this easily ;)

And what exactly is taking you a long time to get right? Is finding good words a challenge, or are you having trouble getting code to work? I should point out that any command that pops off a value removes it from the stack, so in order to keep the value for future use, you will need to add a duplicate instruction before the next print.
Title: Re: Beatnik Esolang Interpreter
Post by: kegwaan on January 19, 2016, 01:13:13 PM
Yeah, finding the right words. Because all of the letters' ASCII codes are big, I just kinda threw a bunch of letters together at the beginning to get to "C". After that I'm just adding and subtracting to get to the next number. Another challenge is writing out part of the code, testing it, trying to remember what I just wrote, then adding to it. Well, I suppose I can just write down what I have as a 'checkpoint'...
Title: Re: Beatnik Esolang Interpreter
Post by: JWinslow23 on January 19, 2016, 01:50:41 PM
I used the online interpreter linked above to both score words and test code. I think I found an online list of all Scrabble words with certain scores, but heck if I can find them again :P
Title: Re: Beatnik Esolang Interpreter
Post by: alexgt on January 19, 2016, 02:51:43 PM
That is really cool JWinslow I like how you can write anything you want as long as it adds up to that value :P
Title: Re: Beatnik Esolang Interpreter
Post by: JWinslow23 on January 19, 2016, 04:34:28 PM
Quote from: alexgt on January 19, 2016, 02:51:43 PM
That is really cool JWinslow I like how you can write anything you want as long as it adds up to that value :P
I don't get your meaning of "as long as it adds up to that value". Not knowing what you're talking about, and because I'm bored, I'm going to post the code of the truth machine formatted in such a way that it looks like a programming language (ignore the Scrabble scores of this one):
input
duplicate
duplicate
output
push 24
duplicate
add
subtract
jump_backwards_not_0 8

As well, here is "code" of what a cat program might look like (I don't have a funny Beatnik equivalent as of yet):
input
duplicate
output
jump_backwards_not_0 3
Title: Re: Beatnik Esolang Interpreter
Post by: kegwaan on January 19, 2016, 06:00:43 PM
Okay, I finished it.
Ha. Laeinorqkkzaelnorstuezkk. To me and I acutely loved. Ha, you. Fear. Ha, me. Fear. Ha, no.
Fear uncivil study. Dig a pit and gone pots. Fear, fear, yogurt twisty abused. Hi, I. Hats windup waters.
Usual awkward wall alcohol abbot. Ape bazooka anagram awake, weep. Act youth Adam. Accept a wound.
Act acts. Acid accused violin. Used ear about abdomen yodel. Gore us, camp kills.


Also, How hard was it to make this compiler/interpreter? Do you think it would be hard to make one for other esolangs, not just brainf**ck but some of the lesser known ones (my favorite one is CalScript, all of the commands use the text "HEE" "HAA"  and "HOO")?
Title: Re: Beatnik Esolang Interpreter
Post by: JWinslow23 on January 19, 2016, 07:41:14 PM
Quote from: kegwaan on January 19, 2016, 06:00:43 PM
Okay, I finished it.
Ha. Laeinorqkkzaelnorstuezkk. To me and I acutely loved. Ha, you. Fear. Ha, me. Fear. Ha, no.
Fear uncivil study. Dig a pit and gone pots. Fear, fear, yogurt twisty abused. Hi, I. Hats windup waters.
Usual awkward wall alcohol abbot. Ape bazooka anagram awake, weep. Act youth Adam. Accept a wound.
Act acts. Acid accused violin. Used ear about abdomen yodel. Gore us, camp kills.


Also, How hard was it to make this compiler/interpreter? Do you think it would be hard to make one for other esolangs, not just brainf**ck but some of the lesser known ones (my favorite one is CalScript, all of the commands use the text "HEE" "HAA"  and "HOO")?
This program is awesome! :D Thank you so much for making it!

It actually wasn't very hard to make this interpreter. The conversions of instructions to TI-BASIC were pretty self-explanatory. In fact, the only difficulties I ran into were input, output, and all the jump instructions. I actually took the time to write a custom input routine that "outlaws" invalid values, which took a while to verify. I also had some trouble with outputting newlines. The jump instructions were hell for a while, but I conquered them. :P

Thinking about applying this to other esolangs was actually my next thought after making this program. I'm considering (don't bet on it happening) making an interpreter for Whitespace. But really, the "easiness' would depend on the esolang, as well as how I would decide to interpret it (looping through the string itself vs parsing it and putting the commands as numbers in a list). For brainf*** I think it'd be trivial (in fact, I might just make that now :P ), for Calscript it'd be a little harder, and for (say) LOLCODE it'd be next to impossible.

EDIT: Cat program:
Repeat extra words, copycat! Go!
Title: Re: Beatnik Esolang Interpreter
Post by: alexgt on January 19, 2016, 07:46:42 PM
I wonder how hard it would be to make in HP PPL O.O
Title: Re: Beatnik Esolang Interpreter
Post by: kegwaan on January 19, 2016, 08:57:35 PM
Quote from: alexgt on January 19, 2016, 07:46:42 PM
I wonder how hard it would be to make in HP PPL O.O
Who knows? Why don't you try it? From what I can see you're the most experienced HP PPL programmer here (no offense to any other HP programmers)
Quote from: JWinslow23 on January 19, 2016, 07:41:14 PM
Thinking about applying this to other esolangs was actually my next thought after making this program. I'm considering (don't bet on it happening) making an interpreter for Whitespace. But really, the "easiness' would depend on the esolang, as well as how I would decide to interpret it (looping through the string itself vs parsing it and putting the commands as numbers in a list). For brainf*** I think it'd be trivial (in fact, I might just make that now :P ), for Calscript it'd be a little harder, and for (say) LOLCODE it'd be next to impossible.
I'd try to make one for Calscript, but if I do that I'd get half-way done, give up on it, and completely forget about all of my other projects  :P So I think I'll leave that to someone else.