If you have some experience in programming, you have probably seen this quote uncountable times. The Hello, world! start is always a good start. With such a simple meaning, it can make you learn a lot of useful things about the language you want to learn. We will take C++ as an example. This is the code that makes that beautiful and simple quote to appear on your screen:
First of all, you will notice the #include <iostream>. From now on, you have to remember to include that library when you want to use the stdout or stdin. Then, we have using namespace std;. Although this line can be omitted, it is way better to include it in our program. Otherwise, we would have to add std:: before every single token calling a function inside the Standard Library, so the fifth line would be:
And that can be kind of frustrating, specially when one of those devilish std:: is missing, and we spend even hours debugging our code until we find out that almost invisible mistake. So, as a life advice, always write that line, even though we are not going to make use of any of its features (don't take that seriously, if you are completely sure you won't need it, you can remove it, mainly for optimization).
All after that, comes the start of the main function: int main(), not a strange thing to someone used to C-based languages. From this, you learn that all of the code that will be executed must be written or called inside this function.
Then we have the cout instruction, which is a normal instruction to make use of the stdout. The endl instruction will just print a new line when used within a cout instruction. And finally, we have return 0;, which simply means that the main() function returns a 0, the integer equivalent of a null value. In modern versions of C++, this can be omitted, and the compiler will obviate it.
But, is this a C++ blog? No. So, why don't we talk now about ALB? In ALB, we can make use of the stdout very easily, as it is shown in this code, that would print Hello, world! on your screen:
So, first of all, you must remember that, in the same way as in C++, where the executed code must be inside the main() function, here, in ALB, that code must be between the BEGIN and END keywords, that indicate the beginning and the end of the executed part of your code, respectively.
And after this, we have an out structure, the equivalent of C++'s cout. Inside curly braces ({}) we have to, first indicate the type of output we want to get (in this case, :string or :str), that can be a string, an integer (:int), a floating-point number (:float), a single character (:char) or a variable of any type (:var). After that, we specify the string we want the program to show ("Hello, world!"). To end the :string output, we also include NEWL, which works exactly the same as C++'s endl.
Finally, we close the out structure and the executed program chunk, with a closing curly brace (}) and the END keyword, respectively. You must also remember that every command must end with a semicolon (;), except for keywords as BEGIN, END, VAR, ENDVAR, and structure-opening commands, such as out, repeat loops, if / elif / else conditional structures...
You should also know that this is not the only way to make use of the stdout in ALB. In the next lesson we will talk about special (or specific) outs, which are basically outs that can just write one output at a time, and of a specific type. That is why there are as special outs as types in ALB.
To sum up, in this first ALB lesson we learned:
#include <iostream> using namespace std; int main() { cout<<"Hello, world!"<<endl; return 0; }
First of all, you will notice the #include <iostream>. From now on, you have to remember to include that library when you want to use the stdout or stdin. Then, we have using namespace std;. Although this line can be omitted, it is way better to include it in our program. Otherwise, we would have to add std:: before every single token calling a function inside the Standard Library, so the fifth line would be:
std::cout<<"Hello, world!"<<std::endl;
And that can be kind of frustrating, specially when one of those devilish std:: is missing, and we spend even hours debugging our code until we find out that almost invisible mistake. So, as a life advice, always write that line, even though we are not going to make use of any of its features (don't take that seriously, if you are completely sure you won't need it, you can remove it, mainly for optimization).
All after that, comes the start of the main function: int main(), not a strange thing to someone used to C-based languages. From this, you learn that all of the code that will be executed must be written or called inside this function.
Then we have the cout instruction, which is a normal instruction to make use of the stdout. The endl instruction will just print a new line when used within a cout instruction. And finally, we have return 0;, which simply means that the main() function returns a 0, the integer equivalent of a null value. In modern versions of C++, this can be omitted, and the compiler will obviate it.
But, is this a C++ blog? No. So, why don't we talk now about ALB? In ALB, we can make use of the stdout very easily, as it is shown in this code, that would print Hello, world! on your screen:
BEGIN out { :string "Hello, world!" NEWL ; } END
So, first of all, you must remember that, in the same way as in C++, where the executed code must be inside the main() function, here, in ALB, that code must be between the BEGIN and END keywords, that indicate the beginning and the end of the executed part of your code, respectively.
And after this, we have an out structure, the equivalent of C++'s cout. Inside curly braces ({}) we have to, first indicate the type of output we want to get (in this case, :string or :str), that can be a string, an integer (:int), a floating-point number (:float), a single character (:char) or a variable of any type (:var). After that, we specify the string we want the program to show ("Hello, world!"). To end the :string output, we also include NEWL, which works exactly the same as C++'s endl.
Finally, we close the out structure and the executed program chunk, with a closing curly brace (}) and the END keyword, respectively. You must also remember that every command must end with a semicolon (;), except for keywords as BEGIN, END, VAR, ENDVAR, and structure-opening commands, such as out, repeat loops, if / elif / else conditional structures...
You should also know that this is not the only way to make use of the stdout in ALB. In the next lesson we will talk about special (or specific) outs, which are basically outs that can just write one output at a time, and of a specific type. That is why there are as special outs as types in ALB.
To sum up, in this first ALB lesson we learned:
- How to specify the executed code (BEGIN and END).
- How to make use of the stdout with an example using the string type (Hello, world! example).
- That every command must end with a semicolon, except for the ones specified above.
- And a bit of C++.
Comments
Post a Comment