Home World Tech Code Introduction to the Elixir Programming Language – 2024 Guide

Introduction to the Elixir Programming Language – 2024 Guide

img source: serokell.io

You’ve probably gone through many articles and books, watched videos, and listened to podcasts on IT and coding. And we can bet that most of you often come across such a programming language as Elixir, but you have not had any idea of its peculiarity and how it differs from others. In this article, we will try to explain it to you.

José Valim designed Elixir as a coding language in 2011. José worked with different programming languages, and two of them were his favorite – Erlang and Clojure. But he thought that it would be cool to bring together the full set of his favorite tools in a single language. Erlang was perfect for him, though there was a lack of other features, which were present in Clojure.

Elixir is a programming language, aimed at creating open source applications. It is a general-purpose, functional, compiled programming language. It was created based on the Erlang language. So, that is why Elixir is almost like Erlang, but with more useful functions.

This article will tell you the basics of the Elixir. However, if you would like to delve deeper into this topic, you will get a whole lot of interesting materials in this blog.

Where to Start?

img source: serokell.io

To dive into coding with Elixir, you must first install it. This process does not take much effort. You can easily do it on platforms such as Ubuntu, Arch Linux, or OS X.

After finishing the process of setting up, you will need to open the shell. You will need to devote great efforts if you dream of becoming a real professional in Elixir. You will study Elixir in this interactive shell, which essentially is a REPL (Read Evaluate Print Loop).

You can immediately start entering certain expressions in the shell, and then instantly get feedback about them.

How to Exit iEX?

Make sure you know how to exit IEx REPL before you launch it. If you already worked with other programming languages, you probably know that you have to press Ctrl + C for this. This way, after pressing this key combination, the Break Menu will open, and then you must press Ctrl + C again, or just the A key, after which the shell closes.

Helpers

In IEx there is a set of so-called helpers. To read their full list, simply enter the following: h ().

Here are a few commands that may come in handy:

h/1 – essentially has the same meaning as the function h considered above, but it requires one argument.

c/2 – collects the data previously entered in the Elixir and requires to enter another variable with a destination to save the file.

Other Basic Things That Are Useful for You To Understand

Numbers

img source: mlsdev.com

Here, we can divide them into two groups: arbitrary-precision integers and floats. Let’s consider in more detail each of them.

Integers: we can type them in one of the following manners: with the help of the decimal base, hexadecimal, octal or binary.

Whenever you have to enter a number greater than 1000, use the underscore for each group of three digits. It will divide hundreds from thousands, millions, etc.

Here are the numbers of other subcategories:

Octal: 0o52.

Hexadecimal: 0xF1.

Binary: а0b1101.

Floating-point numbers

For this sort of numbers, we use dots. There needs to be at least one digit between each dot.

Atoms

img source: dev.to

This term means invariant variables that name. To enter an atom, a colon is used, followed by a set of letters, numbers, or underscores. We can also use at sign @. There is another manner to type atoms. Type a colon and then an arbitrary set of characters, enclosed in quotation marks.

Booleans

You may already have learned from other programming languages that this term means correct or incorrect values of a variable. But eventually, these values flow into ordinary atoms.

Strings

img source: blog.eduonix.com

The Elixir strings are compatible with UTF-8. To apply this feature, all you need is to have arbitrary text enclosed in single or double-quotes. Within the string, we can get interpolated values or escaped characters. If you choose single quotes, you must remember that in this case, binary values are usually used.

Anonymous Functions

Here’s how this function can be written in the program:

fn (argument_list) -> body end

But this feature is not as simple as it may seem at first glance. Because it can have several arguments and bodies.

Tuples

img source: codescrum.com

A tuple is an immutable indexed array. This feature is useful because the array is very easy and quick to resize. However, if you would like to replace the data, it takes more effort, because the very nature of the tuple is invariable.

Pattern Matching

Like any part of the Elixir, pattern matching is a complex and voluminous aspect, and it takes a considerable amount of time and effort to understand it. In this article, we’ll try to explain to you the basic principles of the concept. Though we recommend that you pay close attention to an in-depth study of this issue later.

In this programming language, we use the equal sign as a match operator. To get the hang of this topic completely, you should abstract from what you already have learned about the equal sign from other programming languages.

In such cases, we use the equal sign for pattern matching.

In short and simple words, if a variable is in the left section, it is linked to the value in the right part. The software will try to match the two values if the left side is not variable.

Lists

img source: wallpaperbetter.com

Unlike other languages, in the Elixir lists are program structures made up of a head and a tail.

Conclusion

If you wish to widen your horizon in coding, Elixir is a great choice. It’s relatively easy to start programming and very powerful. It is an ideal programming language for advanced programmers. You can always ask an advise from advanced FP programmers, like these guys.