Lesson 1 [Next]

Hello, World

Text Output

The "Hello, world" program in TLWNN is as follows:

Example one
Hello world
72! 101! 108*!! 111! 44! 32! 119! 111! 114! 108! 100! 33! 10!

There are no string literals in TLWNN.  Instead, all strings must be represented as numbers.  More about how this works will be given in a later lesson.  Meanwhile, all you need to know is that a single ASCII character is represented as the character's ASCII value.  For example, the letter H has ASCII value 72, so the code 72! causes the letter H to be printed.  The code 108*!! is a little more interesting – it causes the letter l to be printed twice.  You'll find out why in a moment.

Any letters are comments.  Note their use in the above example.

Storing Data

TLWNN uses no names, hence the name (oops, lack of a name).  Therefore, we cannot have variables as we know them in the average programming language.

To get around this, TLWNN stores all working data on a stack.  For those who don't know already, a stack is a "last in first out" buffer.  That is, you can only put stuff on and take stuff off at the top.

A number as a TLWNN instruction causes that number to be pushed to the stack (read: put on the stack at the top).  So for example, after the following code

101

the stack will look like this:

101

If the following code were executed instead

171 72

then the stack will look like this:

72
171

You've probably worked out by now what the ! instruction really does: it writes out the string represented by the number at the top of the stack.  Well, if what's at the top of a stack is a number, anyway.  Numbers aren't the only things you can put on the stack.  We'll learn what else can later.  By the way, when ! takes action, what's at the top of the stack is automatically popped (read: removed from the top of the stack).  So after executing the code

171 72!

the stack looks like this:

171

The stack enables stuff to be stored for later use.  It also makes it possible to write the "Hello, world" program with the character codes given backwards:

Example two
Another way of writing Hello world
10 33 100 108 114 111 119 32 44 111 108* 101 72!!!!!!!!!!!!!!

The * instruction duplicates the item at the top of the stack.  You could have just put in another 108 rather than duplicating the existing one, but in the general case you can't always know exactly what it is you need to duplicate.  (There are also times when what you need to duplicate cannot even be written in TLWNN.)

Example three
Yet another way of writing Hello world
72! 101! 108**!! 111*! 44! 32! 119!! 114!! 100! 33! 10!