* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Beatnik Esolang Interpreter  (Read 1649 times)

0 Members and 1 Guest are viewing this topic.

Offline JWinslow23

  • Pi is the coolest number in the history of math. :\
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and Graham's Number
  • Posts: 751
  • Post Rating Ratio: +12/-1
  • Use pi! Pi is the absolute greatest! :(
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Beatnik Esolang Interpreter
« 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 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:
    <5 - Does nothing. The Beatnik Interpreter may mock you for your poor scoring, at its discretion. Low scoring words such as “I” or “of” are probably not good words to program with immediately after stealing all of the interpreter’s cigarettes and stomping on its beret.
    5 - Finds the score of the next word and pushes it onto the stack. Skips the aforementioned next word.
    6 - Pops the top number off the stack and discards it.
    7 - Adds the top two values on the stack together (as described above)
    8 - Input a character from the user and push its value on the stack. Waits for a keypress.
    9 - Pop a number off the stack and output the corresponding ASCII character to the screen.
    10 - Subtract the top value on the stack from the next value on the stack, pushing the result.
    11 - Swap the top two values on the stack.
    12 - Duplicate the top value.
    13 - Pop a number from the stack, and figure out the score of the next word. If the number from the stack is zero, skip ahead by n words, where n is the score of the next word. (The skipping is actually n+1 words, because the word scored to give us n is also skipped.)
    14 - Same as above, except skip if the value on the stack isn’t zero.
    15 - Skip back n words, if the value on the stack is zero.
    16 - Skip back if it’s not zero.
    17 - Stop the program.
    18-23 - Does nothing. However, the score is high enough that the Beatnik Interpreter will not mock you, unless it’s had a really bad day.
    >23 - Garners “Beatnik applause” for the programmer. This generally consists of reserved finger-snapping.

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.
Code: [Select]
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 for reference. Some information about it:

    When you run the program, you are asked to input a Beatnik program. You can use capital and lowercase letters, as well as (meaningless) punctuation. Words are delimited by spaces, so make absolutely sure at least one space is in between words!

    After input, the code is "compiled" (i.e. evaluating the scores according to Scrabble rules, which will be interpreted as instructions by the interpreter. You can press MODE to quit compiling. When it's done compiling, press ENTER.

    At any point during execution, you may press MODE to terminate the program early. Once the program terminates on its own, it will say "Done" on the bottom, and you can press ENTER to quit out of the interpreter.

    Input is handled by using the 8th line. It shows a "?" on the 8th line. Press the number keys to type a number (the printable-ASCII equivalent, if applicable, is shown to the right), press LEFT or DEL to backspace, and press ENTER to input it. You are not allowed to input anything less than 0 or greater than 255 (try it, seriously).

    Output is handled by printing the ASCII character that corresponds to the number popped. If a printable ASCII character is "output", it displays on the top in a kinda-typewriter-like format. If ASCII codes 10 or 13 are "output", it brings the line down. Otherwise, nothing is output.

    The only problem you might run into is conditional jumping through scores of 13-16, with how I interpreted the jumping. I interpreted the jump forward as "increase the instruction pointer by n+1 if jumping, else increase by 2" and the jump backward as "decrease the instruction pointer by n if jumping, else increase by 2". This definition is used by the online interpreter which I used as reference; however, some select Beatnik programs may have trouble with this.

Screenie of the Beatnik interpreter running "Hello, aunts! Around, around, swim!":


Other example programs:

Truth machine (made by me):
Code: [Select]
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):
Code: [Select]
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!


  • Calculators owned: TI-84+, TI-84+ CSE, TI-84+ CE

Offline kegwaan

  • Full User
  • Join Date: Dec 2015
  • Location: 34th digit of pi^1/2
  • Posts: 113
  • Post Rating Ratio: +1/-0
  • I suck, but I'm getting better.
    • /u/CL3M3NTiN3_jr
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #1 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.
  • Calculators owned: TI-84+ SE, TI-84+ CSE
"If it's stupid and it works, it's not stupid."

Offline JWinslow23

  • Pi is the coolest number in the history of math. :\
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and Graham's Number
  • Posts: 751
  • Post Rating Ratio: +12/-1
  • Use pi! Pi is the absolute greatest! :(
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #2 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.

Offline kegwaan

  • Full User
  • Join Date: Dec 2015
  • Location: 34th digit of pi^1/2
  • Posts: 113
  • Post Rating Ratio: +1/-0
  • I suck, but I'm getting better.
    • /u/CL3M3NTiN3_jr
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #3 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.
  • Calculators owned: TI-84+ SE, TI-84+ CSE
"If it's stupid and it works, it's not stupid."

Offline JWinslow23

  • Pi is the coolest number in the history of math. :\
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and Graham's Number
  • Posts: 751
  • Post Rating Ratio: +12/-1
  • Use pi! Pi is the absolute greatest! :(
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #4 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.

Offline kegwaan

  • Full User
  • Join Date: Dec 2015
  • Location: 34th digit of pi^1/2
  • Posts: 113
  • Post Rating Ratio: +1/-0
  • I suck, but I'm getting better.
    • /u/CL3M3NTiN3_jr
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #5 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'...
  • Calculators owned: TI-84+ SE, TI-84+ CSE
"If it's stupid and it works, it's not stupid."

Offline JWinslow23

  • Pi is the coolest number in the history of math. :\
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and Graham's Number
  • Posts: 751
  • Post Rating Ratio: +12/-1
  • Use pi! Pi is the absolute greatest! :(
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #6 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

Offline alexgt

  • Just your friendly neighborhood Ninja Stach Fancy Iron Man
  • Super User
  • Join Date: Dec 2014
  • Location: Behind you
  • Posts: 2611
  • Post Rating Ratio: +6/-1
  • Something should go here...
    • /u/alexgt9123
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #7 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
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Offline JWinslow23

  • Pi is the coolest number in the history of math. :\
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and Graham's Number
  • Posts: 751
  • Post Rating Ratio: +12/-1
  • Use pi! Pi is the absolute greatest! :(
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #8 on: January 19, 2016, 04:34:28 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):
Code: [Select]
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):
Code: [Select]
input
duplicate
output
jump_backwards_not_0 3

Offline kegwaan

  • Full User
  • Join Date: Dec 2015
  • Location: 34th digit of pi^1/2
  • Posts: 113
  • Post Rating Ratio: +1/-0
  • I suck, but I'm getting better.
    • /u/CL3M3NTiN3_jr
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #9 on: January 19, 2016, 06:00:43 pm »
Okay, I finished it.
Code: [Select]
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")?
  • Calculators owned: TI-84+ SE, TI-84+ CSE
"If it's stupid and it works, it's not stupid."

Offline JWinslow23

  • Pi is the coolest number in the history of math. :\
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and Graham's Number
  • Posts: 751
  • Post Rating Ratio: +12/-1
  • Use pi! Pi is the absolute greatest! :(
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #10 on: January 19, 2016, 07:41:14 pm »
Okay, I finished it.
Code: [Select]
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:
Code: [Select]
Repeat extra words, copycat! Go!

Offline alexgt

  • Just your friendly neighborhood Ninja Stach Fancy Iron Man
  • Super User
  • Join Date: Dec 2014
  • Location: Behind you
  • Posts: 2611
  • Post Rating Ratio: +6/-1
  • Something should go here...
    • /u/alexgt9123
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #11 on: January 19, 2016, 07:46:42 pm »
I wonder how hard it would be to make in HP PPL O.O
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Offline kegwaan

  • Full User
  • Join Date: Dec 2015
  • Location: 34th digit of pi^1/2
  • Posts: 113
  • Post Rating Ratio: +1/-0
  • I suck, but I'm getting better.
    • /u/CL3M3NTiN3_jr
  • Gender: Male
Re: Beatnik Esolang Interpreter
« Reply #12 on: January 19, 2016, 08:57:35 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)
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.
  • Calculators owned: TI-84+ SE, TI-84+ CSE
"If it's stupid and it works, it's not stupid."

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games