Now on ScienceBlogs: "Investigative science journalism" and books I like to read [All of My Faults Are Stress Related]

Seed Media Group

The Week In ScienceBlogs: Sign up for our newsletter.

Good Math, Bad Math

Finding the fun in good math; Shredding bad math and squashing the crackpots who espouse it.

Search

Profile

markcc.jpg
Mark Chu-Carroll (aka MarkCC) is a PhD Computer Scientist, who works for Google as a Software Engineer. My professional interests center on programming languages and tools, and how to improve the languages and tools that are used for building complex software systems.

Donors Choose

Other Information

Add this blog to my Technorati Favorites!

Recent Posts

Recent Comments

Categories

Blogroll

Old Topic Indices

Great Online Books

« Stepping Back a Moment | Main | Friday Random Ten for Dec 22 »

Pathological Programming in a Circular Queue

Category: pathological programming
Posted on: December 22, 2006 2:09 PM, by Mark C. Chu-Carroll

Today, I'm going to show you a very simple, very goofy little language called "SCEQL", which standards for "slow and clean esoteric queue language". It's based on nothing but a circular queue of numbers with nothing but 8 commands. It's not one of the more exciting languages, but it can be a lot of fun to figure out how to make the circular queue do what you want it to.

In SCEQL, you've got a circular queue of bytes. You can't *ever* remove anything from the queue. You can alter values on the queue; move things from the front to the back; and add things to it. But that's it.

The commands are:

Instruction Description
= Rotate the byte at the front of the queue to the back of the queue
-Decrement the byte at the front of the queue.
_Increment the byte at the front of the queue.
\Loop: if the byte at the front of the queue is not zero, continue executing at the next instructions; otherwise, jump to the instruction after the matching "/". Roughly equivalent to BrainFuck "[".
/End loop: branch back to the matching "/". Roughly equivalent to BrainFuck "]".
!Grow queue: append a new zero byte to the end of the queue.
&Input a byte, and append it to the end of the queue.
*Output the byte at the front of the queue, and then append it to the end of the queue.

So, how would we write "Hello world"? Not too hard, actually. We need to know the ascii values of the characters. In bytes in ASCII/UTF-8 encoding, "Hello world" is the sequence of bytes: [72,101,108,108,111,32,87,111,114,108,100,10]. So, we need to have a total of 12 bytes on the queue. It starts with one 0, so we need to add 11. Then we need to generate each of those numbers. !!!!!!!!!!! ________________________________________________________________________= _____________________________________________________________________________________________________= ____________________________________________________________________________________________________________= ____________________________________________________________________________________________________________= _______________________________________________________________________________________________________________= ________________________________= _______________________________________________________________________________________= _______________________________________________________________________________________________________________= __________________________________________________________________________________________________________________= ____________________________________________________________________________________________________________= ____________________________________________________________________________________________________= __________= * * * * * * * * * * * *

Neat, huh? How about something slightly less trivial? Input two numbers and add them together? It's surprisingly hard in SCEQL, because the input and output is all done in bytes. So printing numbers isn't particularly easy. In fact, it's a royal pain. So, of course, the solution is: cheat!. I added two new instructions: "<" to read a number from the input, and ">" to print a number to the output. (You can grab the interpreter extended with those two instructions here. With those extensions, a program to input two integers, add them together, and print them out is: <<=\=_==-/=>

That is, input two numbers, and add them to the end of the queue. Circle past the zero that was the initial value on the queue. If the first of the two numbers isn't zero, then rotate the queue to the second number, increment it, rotate back to the first and decrement it, and branch back to beginning of the loop. After ending the loop, rotate to the second number (the result), and print it out.

Just for kicks, here's a long program in SCECL: "99 bottles of beer".

"99 bottles of beer" song in Sceql. Written by Keymaker. Uses UNIX nl (dec 10) in output. _________!=_________!!===_=!===\\-/==\-==_=_==/==\-===_==/=\____ ____________________________________________*====\-//===________ ________________________________________*====------------------- -----------------------------======_____________________________ ___*====________________________________________________________ __________*====_____________*====_____*====*====--------*====--- ----*====\-/======_==\-==_=--==/==\-===_==/====\-=_=-===/=\-==== _=/=\\-/________________________________________________________ ___________________________________________________________*==== \-//====________________________________*====___________________ ____________________________________________________________*=== =---------*====\-/________________________________*====_________ _________________________________________________________*====__ _*====*====_____________*====\-/________________________________ *====___________________________________________________________ ____________________*====-*====\-/______________________________ __*====_________________________________________________________ ___________________________*====------------*====---*====\-/____ ____________________________*====_______________________________ ________________________________________________________*====--- -------------------*====___________*====*====\-/________________ ____________________________*====------------*====\-/===\-==_=_= =/==\-===_==/=\________________________________________________* ====\-//===________________________________________________*==== ------------------------------------------------======__________ ______________________*====_____________________________________ _____________________________*====_____________*====_____*====*= ===--------*====-------*====\-/======_==\-==_=--==/==\-===_==/== ==\-=_=-===/=\-====_=/=\\-/_____________________________________ ________________________________________________________________ ______________*====\-//====________________________________*==== ________________________________________________________________ _______________*====---------*====\-/___________________________ _____*====______________________________________________________ ____________*====___*====*====_____________*====\-/_____________ _________________________________*====\-/__________*====________ ________________________________________________________________ __*====_____________*====__________*====------*====\-/__________ ______________________*====_____________________________________ __________________________________________*====-*====---------*= ===\-/________________________________*====_____________________ _______________________________________________*====___________* ====________*====---------*====\-/______________________________ __*====_________________________________________________________ ________*====_____________*====----------*====\-/_______________ _________________*====__________________________________________ ______________________________________*====---------------*====_ _________________*====*====\-/________________________________*= ===_____________________________________________________________ ____________*====___________*====\-/____________________________ ____*====_______________________________________________________ __________*====_________________*====---*====______*====-------* ====----------*====\-/__________________________________________ __*====------------*====\-/====\-=_=_===/==\-===_==/=_===\\-/==- ==-=/==\-=\-==_=_==/===\-==_===/====\\-/===-=_________=/==/===== _=\-==_=_==/==\-===_==/====\-=_=_===/=\-====_=/=\\-/=-=\-==_=_== /==\-===_==/=\________________________________________________*= ===\-//===________________________________________________*====- -----------------------------------------------==/=\____________ ________________________________________________________________ _________________________________*====_*====\-/_________________ _______________*====____________________________________________ _________________________________*====__*====___*====----------- --*====\-//===________________________________*====_____________ _____________________________________________________*====______ _______*====_____*====*====--------*====-------*====\-/======_== \-==_=--==/==\-===_==/====\-=_=-===/=\-====_=/=\\-/_____________ ________________________________________________________________ ______________________________________*====\-//====_____________ ___________________*====________________________________________ _______________________________________*====---------*====\-/___ _____________________________*====______________________________ ____________________________________*====___*====*====__________ ___*====\-/________________________________*====________________ _______________________________________________________________* ====-*====\-/________________________________*====______________ ________________________________________________________________ ______*====------------*====---*====\-/_________________________ _______*====____________________________________________________ ___________________________________*====----------------------*= ===___________*====*====\-/_____________________________________ _________*====\-/__________*====*====\-/===\-==_=_==/==\-===_==/ ====\-==_=_==/===\-==_===/====/

Comments

1

Egads! You see, I imagine this is what most people reckon programmers do all the time... it certainly bears as much relation to "real" programming as whatever goes on in the 'Hackers' or 'Swordfish' movies.

Posted by: Ithika | December 23, 2006 1:50 PM

2

Reminds me of the drum memories of yore.

Posted by: Jonathan Vos Post | December 25, 2006 3:15 PM

3

And one supposes that a Turing machine can be written in this language.

One does not suppose that and obfuscated SCEQL contest is needed.

I think my modem (which is on a very noisy phone line) spit out that '99 bottles of beer' example. Or something very much like it. Maybe it was '12 days of Christmas'.

Posted by: Stephen | January 3, 2007 1:38 PM

4

A few months ago I wrote a quine in this language. :) It's one of my coolest esoprogs so far (in my opinion, of course). You can find it here:
http://koti.mbnet.fi/~yiap/programs/sceql/quine.sceql

Posted by: Keymaker | January 3, 2007 5:44 PM

5

I actually wrote a very similar language spec called Ouroboros. Its since been taken down from the original server, but I'll try to repost it to the esolang wiki and update it. I never implemented it, however, and merely used it as proof-of-concept for my other pet project at the time, Glypho. Looks messy. I love it!

Posted by: Brian Thompson | April 18, 2007 12:56 PM

Post a Comment

(Email is required for authentication purposes only. On some blogs, comments are moderated for spam, so your comment may not appear immediately.)






Stats

ScienceBlogs

Search ScienceBlogs:

Go to:

Advertisement
Advertisement

© 2006-2009 Seed Media Group LLC. ScienceBlogs is a registered trademark of Seed Media Group. All rights reserved.

Sites by Seed Media Group: Seed Media Group | ScienceBlogs | SEEDMAGAZINE.COM