What is the file extension for Elixir source files that are compiled?
.ex
Which Elixir primitive enables a subprogram to run concurrently in a separate process?
spawn/1
What operator prevents variable rebinding during pattern matching?
^ (pin operator)
What Elixir construct allows multi-way selection and uses pattern matching to determine
which branch to execute?
case
Name the virtual machine that runs Elixir programs.
BEAM (Erlang Virtual Machine)
In Elixir, variables are mutable by default, allowing values to be directly changed in
memory.
FALSE
The MapSet module in Elixir is used to manage collections of unique values and
supports operations like union, intersection, and difference.
TRUE
The ++ and – operators modify the original list in-place when concatenating or
subtracting elements.
FALSE
Elixir source files with the .exs extension are compiled before execution, similar to .ex
files.
FALSE
In Elixir, the do … end keywords are used to delimit code blocks instead of curly braces
{}.
TRUE
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})
{14, 13, 23}
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) rem(n, 2)
b) 0
c) _
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))
12
Based on thIs expression, what list is produced?
result =
Stream.cycle([:a, :b])
|> Stream.take(4)
|> Enum.to_list()
IO.inspect(result)
[:a, :b, :a, :b]
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: #{________}”)
value