[ANN] UNBABTIZED - The language

Gerson Kurz gerson.kurz at t-online.de
Sat Mar 9 12:21:39 EST 2002


Bored, I spent the past few hours writing a small, 100% useless
language. It doesn't have a name, so I call it UNBABTIZED (as in: has
not been given a name yet), which is, right there, a
self-contradiction. What a good start! 

Because the interpreter is written in python, you can enhance your
existing scripting apps by a small, 100% useless language! You might
even want to rewrite all your autocoding (TR) tools in UNBABTIZED if
you find it easier to learn than plain python <neginf.wink>.

Having said that, its a procedural language in that its not a
functional one, and is probably best thought of as one very elaborate
excursion away from brainfuck.

You can write integer literals: "0", "1", and so on.

UNBABTIZED has an array of 1000 memory cells. You can refer to memory
cells:

"°0" is the first memory cell,
"°1" is the second memory cell,
"°999" is the last memory cell.

You can assign data to memory cells:

"!x,y" will assign the value y (either literal or memory cell) to the
memory cell of index x. Obviously, you cannot assign values to
literals.

Instructions are separated by ".", so

"A.B.C" means three consecutive instructions A, B and C.

You can do basic arithmetic:

"~x,y" will set memory[x] to memory[x]+memory[y]
"(x,y" will set memory[x] to memory[x]-memory[y]
")x,y" will set memory[x] to memory[x]*memory[y]
"[x,y" will set memory[x] to memory[x]/memory[y]

and evaluation

"Ax,y" will set memory[x] to memory[x]<memory[y]
"§x,y" will set memory[x] to memory[x]<=memory[y]
"$x,y" will set memory[x] to memory[x]==memory[y]
"%x,y" will set memory[x] to memory[x]>memory[y]
"&x,y" will set memory[x] to memory[x]>=memory[y]
"/x,y" will set memory[x] to memory[x]<>memory[y]

If you need logic functions, write wrapper code using arithmetic
functions and evaluation. You can do output

":x" will write x as char
"@x" will write x as integer

There is no input. There is a philosophy behind this, you know! To my
view, there are two kinds of input, user input and hardcoded input.
User input sucks, and hardcoded input rules, so there.

You can do a DO-WHILE-NOT style loop better expressed as a computed
goto. This c-code

loop_begin:
	...
	if( memory[x] ) goto loop

is written as

","
...(instructions here)...
"-x"

Loops can be nested (at least in theory, but I haven't tested this ;).

There are no comments. Comments are for wimps! Note that Newlines,
Tabs, Spaces etc. are considered comments, too, so they are not
allowed either. Get an editor that can handle long lines, if you want
to mess with UNBABTIZED.

Examples? This

:72.:101.:108.:108.:111.:32.:87.:111.:114.:108.:100

will print "Hello, World", and this

!0,1.!1,1.!2,1.!3,1.,.@°0.!4,°0.!0,°1.~4,°0.!1,°4.~2,°3.!5,°2.A5,10.-5

will print the first ten fibonacci numbers.

The interpreter reqiures Python 2.2 (or higher ;) because of the
changes in lambda-scope. I'm using some of my lambda tricks here. The
code looks very pythonesque, IMHO:

------------------------------- (cut here) -----------------------
import sys

f = sys.argv[1]

o = [0,[],[0]*1000,lambda x:o[4]("o[2]")+"x,o[2][x]%sy)" %x,
     lambda x:x+".__setitem__(",open(f).read().split("."),0,
     1,None,lambda x,y:o.__setitem__(x,y),lambda:o[9](7,o[6]
     .find("°")),lambda:len(o[6][o[8]:o[8]+1]) and o[6][o[8]
     :o[8]+1] in "0123456789",lambda:o[9](6,o[6][:o[7]]+"o["\
     "2]["+o[6][o[7]+1:o[8]]+"]"+o[6][o[8]:]),lambda:(o[11](
     )and(o[9](8,o[8]+1),o[13]())or 0),lambda:o[7]>=0 and(o[
     9](8,o[7]+1),o[13](),o[12]()),lambda:"(lambda x=None,y"\
     "=None:%s)(%s)"%({'!':o[4]("o[2]")+"x,y)",'@':"sys.std"\
     "out.write(str(x)+chr(10))",':':"sys.stdout.write(chr("\
     "x))",'~':o[3]("+"),'(':o[3]("-"),')':o[3]("*"),'[':o[3
     ]("/"),"A":o[3]("<"),"§":o[3]("<="),"$":o[3]("=="),"%":
     o[3](">"),"&":o[3](">="),"/":o[3]("<>"),',':"o[1].appe"\
     "nd(o[0])",'-':"o[2][x] and ("+o[4]("o")+"0,o[1][0]-1)"\
     ",o[1].__setslice__(1,len(o[1]),o[1][1:]))or 0",}[o[6][
     0]],o[6][1:]),lambda:(o[9](6,o[5][o[0]]),o[10](),o[14](
     ),eval(o[15]()),o[9](0,o[0]+1)),lambda:o[0] < len(o[5])
     and(o[16](),o[17]())]

o[17]()
------------------------------- (cut here) -----------------------

One thing though, I wanted to make o[17]() the last item in o, but
that didn't work. Because, at the time o[17] is evaluated, o does not
yet exist. [Long explanation: If you write

o = <something>

then the interpreter will first evaluate <something>, then create o
and assign it. So you cannot refer to o other than in lambda
statements. Even if you were to cheat by writing something like this

o,x = <something>,o[17]()

it wouldn't work, because the right side is treated as a tuple and
evaluated first, and only THEN assigned to the left variables.]

Has anybody any idea of how, with a possibly insane abuse of the
rules, you could put the whole code in an array? Should I write a PEP?

Anyway, enjoy!

Gerson Kurz
http://p-nand-q.com


ps: Congratulations to Jason Orendorff for winning in this years
IOCCC. 




More information about the Python-list mailing list