Looks like I'm going to have to make a short tutorial in how to use the script. Being a postfix language, Dwarf Script has an advantage in learning it, because it allows playing around and improvise, rather than having to compose whole sentences like with prefix or infix languages. Postfix allows for an easy to understand down-to-earth concrete data manipulation, rather than having juggle with dozens of abstractions in your head while writing something. It is data-oriented rather in contrast to function-oriented. The reason people like object-oriented languages is that they are more concrete than functional languages - but they don't go all the way, its a middle ground between data and function oriented languages, and as it turns out unlike OOP which uses an infix notation, data oriented languages doesn't dispose of the possibility of features you want to have in a functional language like multiple dispatch, but, thats for future developement.
If you have used a stack based calculator, then you should be able to easily learn this language, which is a stack based language. What this means that there is an operand stack, on which you have data that you are currently working with, and by typing in a
a) constant, the data ends up on the stack
b) a function, which pops up some data from the stack, manipulates it, and pushes the result back on the stack (sometimes it only does one of these, or neither)
When you start ds, the first thing you see, is two red brackets
[] This is actually the stack, which is empty for now. To fill you you can type in a number, say
5 and press enter
[5]This means 5 is on the stack. Now type in
3[5:3]Now you have two operands on the stack. 3 is on top, because you pushed it in last. Type
+ and press enter.
[8]Since + is a function(an operator) it does not end up on the stack. Instead it picks up 5 and 3, and pushes 8 down. The nice thing is while you are doing this, step by step, you will immediately notice when something goes wrong, unlike in other languages where you write a whole bunch of code and then compile and pray, something screws up and you have no idea where, after which a tedious bug hunt follows. Not so with dwarf script. If something doesn't work, then you can just do it step by step in the konsole.
Still, you have infix taught to you in your school, so its ingrained in your head. How do you type for instance 2 * (6 + 5)
6 5 + 2 *
Which may look confusing to you. This is because you're not used to seeing stuff like this and interpret what it means. You've been taught 2 * (6 + 5) and the complex rules of how to interpret that, you don't even think about, its all automatic because you've been practicing that all the time. But basically what goes on in your head is this:
1. evaluate what's inside parentheses first
2. then evaluate powers and roots
3. then evaluate multiplications and divisions
4. lastly evaluate additions and subtractions
This is called operator precedence. As a programmer you probably have a much deeper hierarchy of up to 15 levels precedence inculcated in your head. Either that or you use parentheses all the time in fear of not having the wrong thing evaluated first. e.g. 1 << 2 | 3 *4 can be difficult for a beginner, but an experienced coder knows what that means because the precedence rules are built in. In Dwarf Script you can forget all that. Any beginner can easily learn it because there are no precedence rules, not even parentheses. Well, actually there are parentheses but they're used for something else.
6 5 + 2 *
Has no parentheses. Instead, the parenthesis that you evaluated first (6+5) is now the very first thing in the code. What you do first, is thus always first you type. In other words you don't have to keep complex rules in your head. You have 5 and 6, and add them together. Then you have the result of that and two, and multiply them together. And thats the order you think, and also the order that computers compute, and also the order in which you write the code
6 5 + 2 *
Yet, you've been taught in school that 2 * (6 + 5) which is totally unintuitive and stupid. But you've been taught to be stupid.
Part 2