The I-Language book
By @MasterOktagon and @ElBe-Plaq.
Contents
1. Why use the I-Programming-Language?
So why should you use the I-Programming-Language? I have tested a lot of programming languages and not found the one I like most. I am generally a fan of Object-Oriented programming languages. I have used Java and C/C++ a lot and can say that I like them very much. Java however has a far to complicated system library built-in and produces (on my opinion) to big projects. Also, Java only supports JIT compiling. While this allows it to be executed on most platforms, this is definitively a drawback in performance. C++ is very powerful but can also be very dangerous. Forgetting to clear some of the objects will trash your RAM over time (any maybe leak some important data). Also a good knowledge over the STL is required for efficient programming.
Therefore the I-Programming-Language tries to fix most of these issues with these design principles:
- Easy-to-learn syntax
- OOP
- Optimized compiler
- Fast
- Compatible with many ecosystems and products
- Easy to extend
2. FAQ
Question 1
Answer 1
Question 2
Answer 2
3. Tutorials
So you want to start a project? Lets just get the basics before that: To compile a single-file program (make it executable), open the command-line in your working directory and type
| Bash | |
|---|---|
You should end up with an .exe (Windows) or plain (Unix) file in the output directory.
Note
This will be a debug build, for releasing look further down.
3.1 Hello World
Lets start with the standard Hello world example:
| Text Only | |
|---|---|
Thats it! Go ahead and compile it!
3.1.1 How does it work?
print will send a print string signal to the standard output (stdout), in this case the command line.
3.2 Guess the number
Lets do something more complicated: A guess the number game! This allows us to learn some more complicated things.
Lets start with a greeting, using the function we learned in our last tutorial:
| Text Only | |
|---|---|
Now we have to generate a random number a store it somewhere to look it up and compare it later. For this we will use a variable. Variables can store all kinds of data, like integers, strings or booleans.
To initialize an empty variable use
| Text Only | |
|---|---|
This variable can now hold an integer. However, because you did not specify the value the variable should have, calling it will result in an value error.
Change the line to hold a variable like this:
| Text Only | |
|---|---|
You now have a variable containing a 3. We will add true random numbers later.
To get the guesses we will need to process input. As you are using output for printing, the way to get inputs from the command line is input.
So add this line:
| Text Only | |
|---|---|
Now we can store an input value too! However if we type something else than a number in the field, you will notice that you get something like
| Bash | |
|---|---|
To solve this write this instead:
| Text Only | |
|---|---|
This is a lot of code, I know. So lets walk through each line.
First we initialize guess with a value of 0. Then we start a new try block. Everything within the braces after the try keyword will be executed, and if a TypeError is raised (specified behind the catch) the code behind catch will be executed. So if you were to pass in Test as the number, it would resort to the fallback value of zero instead.
Now we have to compare the input with the goal. To do that, use the if statement.
| Text Only | |
|---|---|
This compares guess and goal and executes the block of code in the braces if guess is equal to goal (note that we use == for equality to distinguish between the equal and assign symbol, which is =). return Exit makes the program exit with an exit Perfect! You guessed the number right! as the output.
Now lets print the higher/lower.
| Text Only | |
|---|---|
We are again comparing the two values and conditionally outputting lower or higher, but when compiling you will notice that this code will only be executed once, which means it will exit after printing higher or lower. to solve this, wrap this block of code around the rest (except the greeting):
This will ensure that your program will keep running until you guessed right.
Now lets add true random numbers. Because this is a little bit hard for us to program ourself, we will use the built-in random function.
Put this at the beginning of the file to import the random module.
| Text Only | |
|---|---|
Now we need to set our goal variable to a random value. We do this by calling random.randint(0, 25) where 0 is the lowest possible number (exclusive) and 25 is the highest possible number (inclusive). The random indicates that this function is part of the module random which you have imported at the beginning.
| Text Only | |
|---|---|
Now we can add a check if the number inputted is in the range of zero to 25:
| Text Only | |
|---|---|
The final file looks something like this:
Now you can then move the block that checks if guess equals to goal out of the loop.