পৃষ্ঠাসমূহ

Search Your Article

CS

Pageviews

Tuesday, January 31, 2017

Elixir - Overview

Elixir is a dynamic, functional language designed for building scalable and maintainable applications. Elixir leverages the Erlang VM, known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and the embedded software domain.

Elixir - Environment

In order to run Elixir, you need to set it up locally on your system. To install Elixir, you'll first need erlang. On some platforms, elixir packages come with erlang in them.

Elixir - Basic Syntax

We'll start with the customary 'Hello World' program. Start the elixir interactive shell using
iex
After the shell starts, use the IO.puts function to "put" the string on the console output. Enter the following in your elixir shell:
IO.puts "Hello world"

Elixir - Data Types

For using any language, you need to understand the basic data types the language supports. In this chapter, we will discuss 7 basic data types supported by the elixir language: integers, floats, booleans, atoms, strings, lists and tuples.

Elixir - Variables

A variable provides us with named storage that our programs can manipulate. Each variable in Elixir has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.
Elixir supports the following basic types of variables:

Elixir - Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. There are a LOT of operators provided by elixir. They are divided in the following categories:
  • Arithmetic operators
  • Comparison operators
  • Boolean operators
  • Misc operators

Elixir - Pattern Matching

Pattern matching is a technique which Elixir inherits form Erlang. Pattern matching is a very powerful technique that allows us to extract simpler substructures from complicated data structures like lists, tuples, maps, etc.

Elixir - Decision Making

Decision making structures require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
Following is the general from of a typical decision making structure found in most of the programming language:

Elixir - Strings

Strings in Elixir are inserted between double quotes, and they are encoded in UTF-8. Unlike C and C++ where default strings are ASCII encoded and only 256 different characters are possible, UTF-8 consists of 66536 code points. This means that UTF-8 encoding consists of those many different possible characters. Since the strings use utf-8, we can also use symbols like: ö, ł, etc.

Elixir - Char lists

A char list is nothing more than a list of characters. For example:
IO.puts('Hello')
IO.puts(is_list('Hello'))
When running above program, it produces following result:

Elixir - Lists and Tuples

(Linked) Lists

A linked list is a heterogeneous list of elements that are stored at different locations in memory and are kept track of by using references. Linked lists are very useful data structures especially used a lot in functional programming.

Elixir - Keyword lists

So far we haven’t discussed any associative data structures, i.e. data structures that are able to associate a certain value (or multiple values) to a key. Different languages call these different names like dictionaries, hashes, associative arrays, etc.