Elixir Flashcards

(15 cards)

1
Q

What is the file extension for Elixir source files that are compiled?

A

.ex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which Elixir primitive enables a subprogram to run concurrently in a separate process?

A

spawn/1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What operator prevents variable rebinding during pattern matching?

A

^ (pin operator)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What Elixir construct allows multi-way selection and uses pattern matching to determine
which branch to execute?

A

case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name the virtual machine that runs Elixir programs.

A

BEAM (Erlang Virtual Machine)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In Elixir, variables are mutable by default, allowing values to be directly changed in
memory.

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The MapSet module in Elixir is used to manage collections of unique values and
supports operations like union, intersection, and difference.

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The ++ and – operators modify the original list in-place when concatenating or
subtracting elements.

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Elixir source files with the .exs extension are compiled before execution, similar to .ex
files.

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In Elixir, the do … end keywords are used to delimit code blocks instead of curly braces
{}.

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the output of the program?

a = 3
b = 7
c = 10
{[x, y], z} = {[b, a], c}
x = x * 2
y = y + z
z = z + y
IO.inspect({x, y, z})

A

{14, 13, 23}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Fill in the missing code so that the variable result is bound to “even” when n is even and
“odd” otherwise.

n = 7
result = case __________ do
__________ -> “even”
__________ -> “odd”
end
IO.puts(result)

A

a) rem(n, 2)
b) 0
c) _

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Analyze the following recursive function. What value is printed to the console?

defmodule MathOps do
def sum([], acc), do: acc
def sum([h | t], acc), do: sum(t, acc + h)
end
IO.inspect(MathOps.sum([2, 4, 6], 0))

A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Based on thIs expression, what list is produced?

result =
Stream.cycle([:a, :b])
|> Stream.take(4)
|> Enum.to_list()
IO.inspect(result)

A

[:a, :b, :a, :b]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank to complete the output string.

parent = self()
spawn(fn ->
send(parent, {:msg, 42})
end)
receive do
{:msg, value} -> IO.puts(“Received: #{________}”)

A

value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly