Elixir: Basic types and interactive shell
Hello and welcome to my second blog post about elixir, here we will discuss the basic types of elixir, interactive shell and other information.
lets get started.
In my previous blog I showed you how to install Elixir, so you should have it installed now but if you don’t follow my instructions in my first blog to install it:
So lets get started with the basic types within elixir, these types are as follows:
String: are a sequence of characters that can be comprised of symbols or characters as long at they are between double quotes. The following is an example of declaring a string in elixir:
a = “example”
‘a’ now has the string value of “example” associated with it.
boolean: a boolean can have two values either true or false. These can be used for control flow operations such as a an if statement.
a = true
‘a’ now has the boolean value of true associated with it.
Integer: are numerical values can negative or positive but they can have a minimum and maximum limit. these values though cannot contain decimals.
a = 5
‘a’ now has the integer value 5 associated with it.
Float: are similar to integers but can contain decimals.
a = 5.0
‘a’ now has the float value 5.0 associated with it.
Elixir does contain other basic types such as atoms, list, tuples and sigils but for this blog post I will only touch String, boolean, integer and floats because you need to have a understanding of those basic types before you can move on to the more intermediate types which I consider atoms, list, tuples and sigils to be.
So now lets get started with Elixir by using the interactive shell to test out the basic types that I just stated above.
Interactive Shell
- Click the windows start button and type cmd into search bar.
- Select the program cmd.exe
- The command terminal will now appear.
- type iex into the command terminal and wait for it load.
- if you get any errors you might have not installed elixir or have installed it incorrectly.
- you command terminal should look like the following:

You can now test elixir within this shell. So now lets try the following basic types, type the following into the interactive shell and only type one per line.
a = “test”
b = true
c = 5
d = 15.5
We can now test if you properly initialized the above values by using built in modules that ship with Elixir to test the data type of that variable with the exception of the variable ‘a’ as there is no module to test if a variable is a string but we can test it by printing out the current value.
Type the following into the interactive shell:
IO.puts a
the IO.puts command will print out the value of the variable specified after it, in this case it is the variable a. so after typing that command you should see the word test to printed out. You can also use this to print out the other variables just replace ‘a’ with a different variable name.
We will now use built in modules to test the datatypes of the rest of the variables, type the following into the shell:
is_boolean(b)
is_integer(c)
is_float(d)
The first command will test the variable to see if it is a boolean data type, the second will test the integer datatype and third will test the float data type and will return true if it is and false if it is not.
After running these commands individually they should all return true, if one them did not, you have initialized the variable wrong.
In my next blog post I will talk about how we can create our own modules and functions to perform certain actions.