elixir KERNEL 2 Flashcards

1
Q

is_map(%{})

A

=> true

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

What type of Error raised when executing? not nil

A

ArgumentError

*Note: Arguments must be a boolean

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

length([a: 1, b: 2])

A

=> 2

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

hd([5, 6, 7])

A

=> 5

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

is_float(1.2)

A

=> true

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

What type of Error raised when executing?

elem({}, 0)

A

ArgumentError

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

is_map(%Range{})

A

=> true

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

true and “hello”

A

=> “hello”

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

is_nil(nil)

A

=> true

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

to_string(12.3)

A

=> “12.3”

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

false and “hello”

A

=> false

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

rem(8, -7)

A

=> 1

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

elem({1, 2, :hello}, 1)

A

=> 2

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

apply(Kernel, :byte_size, [“cat”])

A

=> 3

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

is_function(fn(x) -> x + 1 end)

A

=> true

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

is_integer(28) == is_number(2.7)

A

=> true

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

tuple = {:clever, “bunny”}

put_elem(tuple, 0, “funny”)

A

=> {“funny”, “bunny”}

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

inspect(:hello)

A

=> “:hello”

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

byte_size(«1, 2»)

A

=> 2

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

inspect(‘bar’)

A

=> “‘bar’”

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

not false

A

=> true

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

inspect [1, 2, 3], limit: 2

A

=> “[1, 2, …]”

23
Q

self() |> is_pid()

A

=> true

24
Q

iex> x = 1

iex> binding()

A

iex => [x: 1]

*Note: Returns the binding for the given context as a keyword list

25
Q

is_list([])

A

=> true

26
Q

to_string([1, 2, 3])

A

=> «1, 2, 3»

27
Q

true or false

A

=> true

28
Q

inspect(15, base: :hex)

A

=> “OxF”

29
Q

What type of Error raised when executing?

:hello or true

A

** (BadBooleanError)
expected a boolean on left-side of “or”,
got: :hello

30
Q

to_string(:hello)

A

=> “hello”

31
Q

map_size(%{a: 1})

A

=> 1

32
Q

to_string(123)

A

=> “123”

33
Q

max(1, :a)

A

=> :a

*Note: term ordering: number < atom < reference < function < port < pid < tuple < map < list < bitstring

34
Q

round(4.49)

A

=> 4

35
Q

node() |> is_binary()

A

=> false
*Note: Returns an atom representing the name of the local node. If the node is not alive, :nonode@nohost is returned instead

36
Q

What type of error would be raised when evaluating?

1 and true

A

** (BadBooleanError)
expected a boolean on left-side of “and”,
got: 1

37
Q

iex> x = 1
iex> x = 2
iex> binding()

A

=> [x: 2]

*Note: Returns the binding for the given context as a keyword list.

38
Q

What type of error is raised when executing?

rem(8, 0.8)

A

** (ArithmeticError) bad argument in arithmetic expression

:erlang.rem(8, 0.8)

39
Q

1 && 4 == 1 and 4

A

=> false

*Note: and accepts boolean as a first argument. && accepts any expression as the first argument

40
Q

fun = fn x -> max(x, 3) end

apply(fun, [2])

A

=> 3

41
Q

Agent.start(fn() -> [] end) |> is_tuple()

A

=> true

*Returns {:ok, #PID}

42
Q

make_ref() |> is_reference()

A

=> true

43
Q
if is_bitstring("bunny") do 
    "bunny is a bitstring"
else
    "not a bitstring"
end
A

=> “bunny is a bitstring”

44
Q

min(self(), :hello)

A

=> :hello

*Note: term ordering: number < atom < reference < function < port < pid < tuple < map < list < bitstring

45
Q

if div(8, 2) == 3, do: “yes”

A

=> nil

*Note nil is returned when condition passed to if doesn’t return true

46
Q

What type of Error raised when executing?

to_string({:ok, “hello”})

A

** (Protocol.UndefinedError)

protocol String.Chars not implemented for {:ok, “hello”} of type Tuple

47
Q

inspect(
“hello” <> «0»,
binaries: :as_strings
)

A

=> “"hello\0"”

48
Q

inspect(
“h” <> «0»,
binaries: :as_binaries
)

A

=> “«104, 0»”

49
Q

iex> x = 1
iex> y = 2
iex> binding()

A

=> [x: 1, y: 2]

*Note: Returns the binding for the given context as a keyword list.

50
Q

What type of Error is raised when executing?

hd([])

A

ArgumentError

51
Q

true and 4 and 5

A

** (BadBooleanError)
expected a boolean on left-side of “and”,
got: 4

52
Q

byte_size(«145::24, 5::4»)

A

=> 4
*Note: if the number of bits in bitstring is not divisible by 8, the resulting number of bytes will be rounded up (by excess)

53
Q

is_function(fn(x) -> x + 1 end, 2)

A

=> false

*Note: Returns true if term is a function that can be applied with arity number of arguments; otherwise returns false

54
Q

true or “hello”

A

=> true
*Note: If the first argument is true, true is returned; otherwise, the second argument is returned. Requires only the first argument to be a boolean since it short-circuits.