Beginning my journey with elixir Part I - problem with mix and 5 most interesting things I learned so far.
Tags: beginners, elixir, tutorial
Published: 2021-02-03 01:33:01

Currently, I am a student of computer science and I am dedicated to programming, I tried different technologies such as node, python but elixir excites me the most and with this technology I bind my professional future. In this series, I would like to share my adventure, successes, and problems I encountered. Hope you will enjoy this series 😀

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x2jl8l1uu6psczgvynu6.png)

I started from learning basics from [Elixir school](https://elixirschool.com) and [Elixir webpage] (https://elixir-lang.org). Everything was going well with learning until I got an error when I had to use [mix](https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html). I installed elixir with [instructions](https://elixir-lang.org/install.html). I am using Linux Mint and the error I got when trying to create a new app was:
```
╰─❯ mix new app
** (Mix) Application name must start with a letter and have only lowercase letters, numbers, and underscore, got: "app". The application name is inferred from the path, if you'd like to explicitly name the application then use the "--app APP" option.
```
I couldn't find an answer on StackOverflow so I decided to ask on the `elixir` channel on discord and good people advised me to install elixir via `asdf`. It is an extendable version manager that can be used to install elixir properly [link](https://asdf-vm.com/#/core-manage-asdf).

I removed elixir and erlang then installed the latest versions of them  using `asdf`:
```
1) asdf plugin add erlang && asdf plugin add the elixir
2) asdf install erlang latest
3) asdf global erlang <version>
4) asdf install elixir latest
5) asdf global elixir <version>
```
Thankfully, I can now enjoy the functionality of the `mix`.

I will now move on to the most interesting things I learned.

1.`Pin operator` it makes assignment when the left side if the match includes variables. Example:
```
iex> x = 42
42
iex> ^x = 44
** (MatchError) no match of right-hand side value: 44
```
As you can see when I tried to match `x` with `44` I got an error above.

2.`Cond` is used to match conditions similar to `if-else` or `else` in other languages. Example:
```
iex> cond do
...>   "apple" == "banana" -> "Incorrect"
...>   true -> "Catched all"
...> end
"Catched all"
```

3.`Pipe operator` it takes the result of one function and passes it on as the first parameter of another expressions. Example:
```
iex> "HEllo WoRld" |> String.downcase() |> String.split()
["hello", "world"]
```

4.`Documentation of Modules and functions` Example:
```
defmodule Calculator do
  @moduledoc """
Provides a function `add/2` to add two numbers and print them out
  """

  def add(x,y) do
   IO.puts x+y
  end
end

```
You can access Calculator documentation by using the `h` helper function:
```
iex>c("file.ex") 
[Module]
...> Calculator.function(5,4)
9
:ok

iex> h Calculator

                Calculator

Provides a function add/2 to add two numbers
```
5.`Start new project using mix` Example:
```
$ mix new app

```
Output:

```
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/app.ex
* creating test
* creating test/test_helper.exselse
* creating test/app_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd app
    mix test

Run "mix help" for more commands.

```



#### This is all that I wanted you to present in Part I. Have a nice day and stay tuned for the next update. Bye 👋.