09 September 2015

Tidbits of 8th


Basics


In this post I will show you the very basics of 8th.

8th is a so called stack based language, just like it's predecessor Forth.

What is a stack?

To illustrate that, I've added a picture of a toy which often is used by toddlers.

The pole of the toy has a bottom plate attached to it, so rings cannot be removed at the bottom.

To remove the topmost ring, you just pick it. This is called popping.
So, when you pop the stack, you remove the topmost "item".

When, instead you wish to remove the second ring, you must remove (pop) the first ring first and only after that you can remove (pop) the next ring!

OK. So far the analogy with the toy. In 8th the stack is "virtual", which means that it is an area in main memory where you can stack "items" (where items can be numbers, strings etc.).

More operations on the stack

It would be a real problem if we could only pop an item from the stack.
So there are quite a lot of operations available. We'll see a few here.

Push is the operation to put a new item on top of the stack. In analogy with the toy this would mean we place a new ring upon the topmost one.

Thinking about that, we must realize that this is special in some way. Why? Well assume the length of the pole of our toy is to short and we push a new ring onto it, what would happen?

Same applies for an 8th stack. Space for the stack is reserved in advance. If you run out of stack space we get a nasty error message from 8th, warning that we use too much stack space.

Also be careful when popping the stack. What happens when you pop and there is no stack item left to pop?

So, an 8th programmer should use the 8th stack thoughtfully. If you do so, it won't ever be a problem!

Magic

Here the analogy with the toy must come to a real halt.

In 8th there are stack operations possible which would be uinimaginable for the toy.

For example the dup operation.  The dup operation magically creates a copy of the topmost stack item and pushes that onto the stack. So, after the operation the topmost two items are copies of each other.

By the way: we call the topmost item on the stack TOS (Top Of Stack).

Another magic operation is over. The over operation makes a copy of the one but TOS item and pushes it on TOS.

The 8th notation for stack operations

In 8th we use a special notation for stack operations. These are called SED (Stack Effect Diagrams).

A SED is only a description and not a compiled or interpreted something.
Hence it must start with a \ in order to make it a comment.

The SED for pop is as follows:
        \   x   --
OR
        \   st   x   --   st
Explanation:
     1. the \ character (in 8th terms called the \ word) make the SED an 8th comment
     2. left of the -- are the stack items relevant for this operation before the operation starts;
         this means that there can be much more items on the stack, but they are not relevant now
     3. the -- stands for the operation that is performed (pop in this example)
     4. to the right of the -- are the relevant stack items resulting after the operation

In the latter form of SED st stands for the rest of the stack items (not relevant for this operation).

Example of SED for push:
       \   --   x
OR
       \   st   --   st   x
This means that a new item x will be put on TOS.


Example of over:
      \   x   y   --   x   y   x
OR
      \   st   x   y   --   st   x   y   x
This means that before the operation, first the item x has been pushed onto the stack and after that y has been pushed onto the stack. So y is on TOS when the operation begins.
After the operation we see that x and y are still present on the stack (and in the same order) but that a copy of x has been pushed to TOS. Because the copy of x kind of jumps over y, the operation is called over.

NOTE: the letters or names for stack items in an SED are free to choose. Shorter is nicer, but you can make them a bit meaningful. E.g. numbers could be represented by n1, n2, etc. and strings by s1, s2 etc.

How to use the stack operations in 8th according to their SED?

Example of pop:
      pop
Huh? Yes, that's the only thing we have to write.
Now we need to remember (in our poor head) what it does from the SED of pop.
Effectively the TOS was taken from the stack and the second item became TOS.

Now an example for over, which is a bit more understandable:
      2   3   over
On TOS there is the number 3 and in second position is 2before the operation.
After the operation the second item (2) has been copied and pushed over 3.
That means that the relevant part of the stack now is:   2   3   2

Conclusion

We have seen a few tidbits about 8th and the stack.

If you have any questions feel free to ask here.

Better still is to go to the website of 8th http://8th-dev.com where is also a very friendly forum!

06 September 2015

Why 8th?

Why 8th?

This is always the question. So, why another language again?

First I wil give a very short intro about 8th.

8th is a general purpose language built on the filosophy of the famous language Forth, once created by Charles Moore.

Where Forth shines especially close to the the hardware level, 8th has to offer much more.

First and foremost 8th is a tool to develop native apps for almost any platform, including Android, IOS, Linux and Windows as well as several embedded devices like the Raspberry Pi.

So, why 8th?
  • really multiplatform
  • can be embedded
  • ready for the IOT (Internet Of Things)
  • easy and clean syntax
  • single language (e.g. no mix of Javascript, CSS and HTML)
  • not dependent on a platform like JVM or .NET
  • cheap
  • fast development cycle due to 8th's dual nature (interpreter / compiler)
  • very helpful developer answering quickly
  • friendly community forum
In following blogposts I will try to give short code examples to bring you up to speed with 8th's syntax and filosophy.

Have a look at their website http://8th-dev.com

Disclaimer

This is the first entry of this blog and immediately I need to add a disclaimer ;-)

DISCLAIMER: I am not a successor of the writers of the Gospel: Matthew, Marc, Luke and John.

That said, personally I believe that what they wrote is the truth.

What is this blog about then?

Well, it is all about a new programming language called 8th. You van read more here: http://8th-dev.com

Wish you happy reading in the future!