Fatskills
Practice. Master. Repeat.
Study Guide: All The Useful Elixir Interview Questions & Answers
Source: https://www.fatskills.com/software-engineering/chapter/all-the-useful-elixir-interview-questions-answers

All The Useful Elixir Interview Questions & Answers

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~5 min read

Q 1. What is Elixir? Explain.
Elixir is a functional and dynamic language that is designed for building scalable applications. It is based on Erlang language VM which is known for running fault-tolerant and low-latency systems. Offering useful tooling and extensible design, Elixir is supported by meta-programming and polymorphism.

Q 2. Explain the advantages of Elixir.

Scalability and Extensibility
Fault Tolerance
Interactive and fast development
Strong metaprogramming
Simple syntax

Q 3. What is the latest version of Elixir?
The latest version is 1.7.3 which was released in August 2018.

Q 4. How many types of data types does Erlang provide?
Erlang provides two types of data types:

Constant data type: This data type cannot be split into primitive subtypes as it consists of Atoms and Numbers.
Compound data type: This data type is used to put together other data types, and it consists mainly of lists and tuples.

Q 5. What is Open Telecom Platform (OTP)?
An open source platform, OTP is a huge set of Erlang libraries to do all kinds of tasks, from assembling ASN.1 to providing a server.

Q 6. How is run time error handled in Erlang?
Using Catch or Try can help prevent run-time errors from causing the process to terminate. Catch Expr throws value of the expression, except when an exception occurs during the evaluation phase. Try Exprs is nothing but the enhancement of catch with the added ability to identify and handle the desired exception class.

Q 7. What are the modules? How can a module be stored?
Erlang enables to put together code into modules, which consists of functions. A module introduces local scope of functions, both Public and Private. A module is stored in a file named '.erl.' Make sure the file basename and the name of the module are the same.

Q 8. How is a 'process' created in Erlang?
A process is created by calling spawn, which forms a process and returns the pid. Here's how you can do it:

Spawn (Module, Name, Args ) -> pid ()

Q 9. What is guard sequence?
The function clauses can be protected using guards, but a clause can only be protected if the guard holds it. A guard sequence is separated by a comma (,) and semicolon (;). The guard sequence can only be true when at least one guard is true.

Q 10. What are some of the valid guard expressions?
The valid guard expressions are Atom true, Other constants, Calls to the BIFs specified, Term Comparisons, Arithmetic Expressions, Boolean Expressions, and Short-circuit Expressions.

Q 11. How is a message sent and received in Erlang?
For sending a message, you can use an exclamation mark (!) as the operator. The syntax that you can use for sending a new message is Pid ! Message.

For receiving a message, you can use Pattern Matching from the message queue receive a statement.

Q 12. Explain what are Spawn_link 1l3 and Spawn/ 1l3?
Spawn/ 1l3 creates a new process and return pid. In the system scheduler queue, the new process is created so that it runs later.

Spawn_link/1l3: provides the same functionality as spawn/1l3 but with an additional link that gets automatically created between the caller and the new spawn process.

Q 13. What is the syntax to write Macros?
define ( Const, Replacement )

define ( Fun ( Var1 , Var2, …., Var ) , Replacement )

Q 14. What are some of the pre-defined Macros in Erlang?
Here are the pre-defined Macros:

?MODULE
The name of the current module.

?MODULE_STRING.
The name of the current module, as a string.

?FILE.
The file name of the current module.

?LINE.
The current line number.

?MACHINE.
The machine name, 'BEAM'.

?FUNCTION_NAME
The name of the current function.

?FUNCTION_ARITY
The arity (number of arguments) for the current function.

?OTP_RELEASE
The OTP release that the currently executing ERTS application is part of, as an integer. For details, see erlang:system_info(otp_release). This macro was introduced in OTP release 21.

Q 15. What is a record?
The data structure that is used for storing a fixed number of elements is referred to as a record. Expressions are then translated into tuple expressions during the compilation record.

The Record is defined by the name of the record, which is followed by the field names. The record and field names should be atoms.

record (Name, { Field1 [= Value] , … FieldN [= ValueN] } )

Q 16. What is the command for accessing record field?
Expr#Name.Field. This command returns the value of the mentioned field. To return the position of the specified field, you can use the command #Name.Field.

Q 17. What is Erlang Port Mapper Daemon (epmd)?
It is a small server that is used for establishing distributed communications. This name server is responsible for mapping the node names to the machine addresses.

Q 18. What are the main operators in Elixir?
Following are the main operators:

Arithmetic operators
Comparison operators
Boolean operators
Misc operators

Q 19. What is String Interpolation?
It is a way to build a new string value where the code is wrapped in curly braces and '#' function.

Example:
                                                   
x = "Apocalypse"
y = "X-men #{x}"
IO.puts(y)
x = "Apocalypse"
y = "X-men #{x}"
IO.puts(y)

Q 20. What role does Crypto Module play?
The crypto module decrypts project applications by using digital signature and hashing function and.

Example:
                                                   
IO.puts(Base.encode16(:crypto.hash(:sha256, "Elixir")))
IO.puts(Base.encode16(:crypto.hash(:sha256, "Elixir")))

Q 21. Define Structs.
You can define Structs by using the defstruct. Here is how you can do it:

Example:
                                                   
iex> defmodule User do
...> defstruct name: "John", age: 27
...> end
iex> defmodule User do
...> defstruct name: "John", age: 27
...> end