OCaml - List - Creating a list

As all programming languages, it is possible to create lists in OCaml.

So, let's see this, right now with new examples.
We will indeed create two functions, one of ints and another of strings.

For the ints:

OCaml - Function - Creating a getter to retrieve an element of a tuple

OK, this is not really a getter implementation like we can have it in other object-oriented programming, but it is close of it.

We have first to create an human variable with a tuple ("name", age).
Then we have to create two getter functions to retrieve the first and the second parameter of this human variable.

OCaml - Function - Using recursion

OCaml is a fully recursive language. So using recursion is completely natural.
We will see in this example how to create an easy recursion of a classic factorial. This in two different manners.
These two ways of using recursion are strictely the same, the type of the function and the result as well of course.

OCaml - Function - Creating an easy function

In this tutorial we will see how to create a function in OCaml language.
It will be an easy function to understand how it works.

We will create a function that returns an int + 1.
Here the code:

OCaml - Variable - Creating variables

For creating variables in OCaml we need to use the let keyword.

The syntax to create a variable is the following:

 

# let myVar = 90;;

When you type enter, it will be displayed the type of your variable:

 

OCaml - Utilities - Using the rlwrap command

When you use OCaml on Linux for example, you cannot by default using the arrow from your keyboard, neither the completion.
If you try to use them you will have something like that:

# ^[[A^[[D^[[C^[[B^[[D^[[A^[[C^[[D^[[B^[[C

But there is readline wrapper named rlwrap that will help us in this task!

UNIX & GNU/Linux - System calls - Using time()

It is sometimes useful to display the current date in your terminal.
For that the time() system call function is the best one.
Let's see an example within this tiny tutorial of C programming language:

C++ - Tips'n Tricks - Converting a std:string into an int and converting an int to a std::string

For the C, we had the famous atoi() function, but for C++, how can I convert a std::string into an int?

C++ - Keyword - virtual

The virtual keyword is used in different ways in C++.

The most common way to use it is before a destructor.
Indeed, with this virtual keyword we can specified that the children of a class will be deleted before its parent.

Let's see it with a tutorial.

C++ - Makefile - Adding flags

A personal Makefile is sometimes better than a Makefile generated by default by your IDE, such Eclipse or Visual Studio C++ for example.

Pages

Subscribe to BadproG.com RSS