For beginners

Topics

1. What is a programming language?
2. Who's playing? A threesome!
3. What programms look like
4. What are variables?
5. What are Subs?
6. What's a '\' character and what do I do with it? Character strings!


1. What is a programming language?
A programming language is a language that computers understand.
Humans can use this language to order computers to do whatever they want, computers are slaves and that's politically correct!
I call this absolute freedom 'Computer Plasticity'. Indeed, as you can turn a ball of plasticine into anything you want, so can you with a computer.
However, computers are -so far, quite stupid. You can't use every day's language to ask your computer to do something. That's why most of the languages they use are simplifications of our human languages.
The main thing in computer languages is that they must be very precise. A computer can not understand the sentance 'Put that there'. That's too subtle.
Programms are stored in files.


2. A threesome
Sorry if you expected something more, ermmmm, more adult here, but the threesome I'm talking about is this one, sorry...

The programmer writes programms.
The computer runs the programms.
The user uses the programmes.
Of the three, guess whose part is the most interesting?
Yes it's the programmer's. The computer has no notion of what is pleasurable and what is not anyway! But the programmer must first write programmes, then he has to imagine he's the computer:
'Ok: I have this variable that contains that, this loop that does that, and this sub that scrambles everything... Damn!'
Then the programmer must imagine he/she's wearing the user's shoes in order to make the user's job easy. Ok, that's the part that's the less frequently played, unfortunately, that might be the most important.
Programming can be frustrating at times, but it can also be utterly rewarding, especially when, as is the case with Aptilis, it allows you to do spectacular things with very little sweat. Think about on-line purchase orders, graphics on the fly, games!! The world is yours!!


3. What programms look like
Aptilis programms, like most programms, are text files. In Windows, that means you can simply use the notepad to write a programm. In Unix, you'll have the less friendly (but they say, more powerful once you know how to use it...) vi.
Here's an example of a programm:

sub main

        print("Hello World!")

end sub

If you want to try it, save this file as "test" with the notepad (test.txt under Unix) in the directory where you put 'aptilis.exe', open a DOS box, go to the directory where aptilis.exe is and at the command prompt, type:

aptilis test.txt
Unix users should type ./aptilis.exe test.txt
What we've done was to write a programme, save it and run it.


4. Variables
Variables are boxes in which you put values, like a number.
You have probably heard about pi, that 'greek' number that knows how to compute all things circular. Well, you don't want to type '3.141592654' all the time. First, because you don't want to go into a math encyclopedia every two lines of code and second, you want something shorter, more readable. Let's see how to create a variable:

pi = 3.141592654

In aptilis, that means: put the value 3.141592654 into the variable 'pi'. I hear someone ask: 'No declarations, then?'
Nope.
If you don't know what a declaration is don't worry, you don't need to, unless you want to use Java or C.


5. Subs
Subs are pieces of programms, where you usually do one thing. By partitioning your programms in subs, you'll make your task easier when it comes to find bugs (errors). In all cases, you need at least one sub in Aptilis:
the main sub.
If there is no sub called main, then Aptilis will be lost and won't be able to run your programme. The sub main is an agreed meeting point between you and Aptilis.
Subs can also be seen as little factories: You feed them with raw materials (the parameters) and they return a finished product (the return value).
This sub is fed the radius of a circle and returns its circumference:

sub circumference(r)

        return 2 * 3.141592654 * r

end sub

There are two kinds of subs: predefined subs which have already been written for you, like 'print', 'saveFile', etc... and the ones you will write, which are simply called 'subs'.


6. The '\' character, and how to put a " in a string, etc.
You put a string into a variable as follows:

name = "John Doe" $

Now how could you insert a double quote? Because double quotes mark the begining and the end of the string, if you inserted one or more of them within the string, that would first cut it and then confuse the Aptilis parser and you would get an error. The trick is to say: 'Hey! Attention please! There's gonna be a special character!!". You do that by typing a '\', in other words, a back-slash. For my fellow dyslexic programmers, that's the one on the left of the keyboard, not far from the 'Caps Lock' key. Here's what it's looking like:

name = "John \"Duck Face\" Doe" $

Now, if the back slash is reserved to indicate special characters, how do you type the backslash itself?? Here's the solution:

path = "c:\\directory" $

You just type two of them.

Here are all the special characters Aptilis knows:
\n Line Feed (print to next line)
\r Carriage return, might be needed for DOS files before a '\n'
\t Tab character
\" double quotes
\\ backslash
\0 ASCII 0
Aptilis also understands the '\xHH' notation where HH is a hexadecimal number, from 0 to 255, so that you can get the whole ASCII set.