Elixir Flashcards
terminal line for the console?
iex
Framework used with Elixir?
Phoenix
Which virtual machine do Elixir programs compile to?
Erlang
How do Erlang and Elixir work together?
The Erlang VM runs as one operating system process, and by default runs one OS thread per core. Elixir programs use all CPU cores.
Why is Erlang faster than other platforms?
Erlang is faster than other platforms because it doesn’t allow mutability or shared memory by default.
Erlang is a _____ programming language.
functional
How does functional programming treat computation?
As the evaluation of functions, and avoids mutable state and data. immutable data structures and single assignment variables
Main difference between Obeject & Functional Programming?
Object doesn’t enforce isolated state. Values can be mutated in place. Functional has immutable data structures and single assignment variables
What is the Elixir match operator?
the = operator is the match operator. It enables us to assign and then match values
iex> {a, b, 42} = {:hello, “world”, 42}
What is Mix and what does it do?
it’s an Elixir development tool
Creates projects
Compiles projects
Runs ‘tasks’ (i.e running tests or generating documentation)
Manages dependencies
What is the CL for generating new Elixir project?
mix new name-of-project
How is code organized in Elixir?
In modules. A collection of different methods or functions.
CL to compile and run your project in the Elixir console?
iex -S mix
What is CL to access the Elixir console?
iex = interactive Elixir shell
How do you call a method on a module?
with .
you can use or leave out the parentheses
Cards.hello
Cards.hello()
Which is convention? single or double quotes
double quotes
console CL for refreshing your console with updated code?
recompile
Main diff between object and functional programming?
With functional, you can’t create classes or copies or instances of a class. It’s just a collection of methods in a module. You pass in data and the module applies a method to that data.
But you do have assignment variables
Term for number of arguments a method accepts?
arity
Method as an ‘arity’ of 1 (argument)
How does Elixir handle variables?
Variables are immutable. We never modify any existing data. We create and return a new one/copy.
Syntax for a “for” loop?
for element
Syntax for string interpolation?
{ }
What does a nested for loop produce?
nested lists/arrays
Method to check if a list contains a particular element?
Enum.member?(list, element)
What is a tuple?
Like an array where each index has a special meaning.
Uses { }
Method to randomly separate a list by a given value?
Enum.split(list, num)
returns a tuple with two lists. separated list at index 0, rest of the list at index 1)
How is Erlang code identified?
with a colon :
How do Elixir and Erlang work together?
Elixir sits on top of Erland and we can call Erlang code at any time.
Elixir version of an if statemement?
case variable do
:ok -> code
:error -> code
end
What are atoms?
premitive variables to handle status and control flows. similar to strings, but an atom is codified.
:ok
:error
What does _variable mean in pattern matching?
We know there is going to be an element there in the pattern match, but we don’t want to use it (but we still have to put it in for the purpose of pattern matching)