Intro to Erlang (L19) Flashcards

(51 cards)

1
Q

What is Erlang known for?

A

Erlang is the king / queen of concurrent languages.

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

Which concurrency framework is based directly upon the Erlang language?

A

Java’s Akka concurrency framework.

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

Like Clojure, Erlang is a direct mapping of the LISP language.

A

False.

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

Erlang runs on which virtual machine?

A

BEAM.

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

Name a language that run’s on Erlang’s virtual machine.

A

Elixir.

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

What’s the name of Erlang’s interactive command line?

A

Eshell.

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

What is the suffix of a compiled Erlang file?

A

.beam

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

What command is used to compile Erlang code?

A

erlc

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

What command is used to run compiled Erlang code?

A

erl

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

What is the suffix of a Erlang source file?

A

.erl

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

Are there type declarations in Erlang?

A

No - types are inferred from context.

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

What are Erlang’s simple types?

A

Integers, floating point values, strings.

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

What is the max size of Erlang’s integers?

A

Erlang’s integers are of arbitrary length.

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

Do Erlang strings use single or double quotes?

A

Double.

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

Is there a boolean type in Erlang?

A

No, but there are true/false constants that are returned by conditional checks.

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

Erlang uses prefix notation for its operations.

A

False.

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

Erlang variables can only be reassigned once.

A

False, they can only be assigned once - attempts to reassign generate errors.

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

Erlang variables must begin with what?

A

A capital letter.

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

When are commas used in Erlang?

A

Commas are used between function arguments and between expressions in a function body.

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

When are semi colons used in Erlang?

A

Semi-colons are used between alternate forms of a function.

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

When are periods used in Erlang?

A

A period (plus a whitespace char like a newline) is used to terminate a complete expression.

22
Q

What are Erlang’s 4 composite data structures?

A

Tuple, list, record, map.

23
Q

Erlang tuples are analogous to what data type in C?

24
Q

Define a tuple with 2 elements.

25
In practice, what is the first element of an Erlang tuple?
An atom.
26
What are atoms?
Constant labels/strings.
27
What is the syntax restriction of Erlang atoms?
They must begin with a lowercase character.
28
What character is used for comments in Erlang?
%
29
Use pattern matching to save (only) the pig's age to another variable. P = {pig, "Jim", 43}.
{pig, _ , Age} = P.
30
Define an Erlang list of two values.
List1 = [1, 2].
31
Can types be mixed in Erlang lists?
Yes.
32
What is stored in List2? List1 = [1, 2]. List2 = ["x" | List1].
["x", 1, 2]
33
What do X and Y equal to? List1 = [1, 2, 3]. [ X | Y ] = List1.
X = 1 (head), Y = [2, 3] (tail).
34
What function produces List3 from List1 and List2? List1 = [1, 2, 3]. List2 = [4, 5, 6]. List3 = [1, 2, 3, 4, 5, 6].
List3= lists:append(List1, List2).
35
What function deletes all ocurences of an element from a list?
Result = lists:delete(Element, List).
36
What function sorts an Erlang list?
SortedList = lists:sort(UnsortedList).
37
Does Erlang's sort function sort in increasing or decreasing order by default?
Increasing.
38
What function splits an Erlang list into two lists at a specified index?
{Prefix, Suffix} = lists:split(Position, List).
39
What function reverse an Erlang list?
Reversed = lists:reverse(List).
40
How do you define a record in Erlang?
-record(name, { key1 = val1, key2 = val2, }).
41
Record keys and values may be of any type in Erlang.
False - keys must be atoms.
42
The name of a record must be an atom.
True.
43
In the below record definition, val1 and val2 are necessarily the values of key1 & key2 once this record is "instantiated": -record(name, { key1 = val1, key2 = val2, }).
False, val1 & val2 are default values for key1 & key2, respectively.
44
Must a key be given a default value in an Erlang record definition?
No.
45
What is the value of R1's age? -record(person, {name = unknown, age}). R1 = #person{}.
Age is undefined.
46
Create a record wherein age is defined explicitily, using the definition below. -record(person, {name = unknown, age}).
R1 = #person{age = 99}.
47
Access the "age" field of a "person" record stored in variable R1.
Age = R1#person.age.
48
Where are record declarations generally declared?
In separate file(s), and then included in the current files.
49
Included files in Erlang are given what extension?
.hrl
50
Write the code to import declarations from an external file called "person.hrl".
-include(“person.hrl”).
51
Define the same map using two different syntaxes.
M1 = #{man => “joe”, women => “sue”}. M2 = #{man := “joe”, women := “sue”}.