Intro to Erlang (L19) Flashcards

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?

A

structs

24
Q

Define a tuple with 2 elements.

A

{1, 2}

25
Q

In practice, what is the first element of an Erlang tuple?

A

An atom.

26
Q

What are atoms?

A

Constant labels/strings.

27
Q

What is the syntax restriction of Erlang atoms?

A

They must begin with a lowercase character.

28
Q

What character is used for comments in Erlang?

A

%

29
Q

Use pattern matching to save (only) the pig’s age to another variable.
P = {pig, “Jim”, 43}.

A

{pig, _ , Age} = P.

30
Q

Define an Erlang list of two values.

A

List1 = [1, 2].

31
Q

Can types be mixed in Erlang lists?

A

Yes.

32
Q

What is stored in List2?
List1 = [1, 2].
List2 = [“x” | List1].

A

[“x”, 1, 2]

33
Q

What do X and Y equal to?
List1 = [1, 2, 3].
[ X | Y ] = List1.

A

X = 1 (head), Y = [2, 3] (tail).

34
Q

What function produces List3 from List1 and List2?
List1 = [1, 2, 3].
List2 = [4, 5, 6].
List3 = [1, 2, 3, 4, 5, 6].

A

List3= lists:append(List1, List2).

35
Q

What function deletes all ocurences of an element from a list?

A

Result = lists:delete(Element, List).

36
Q

What function sorts an Erlang list?

A

SortedList = lists:sort(UnsortedList).

37
Q

Does Erlang’s sort function sort in increasing or decreasing order by default?

A

Increasing.

38
Q

What function splits an Erlang list into two lists at a specified index?

A

{Prefix, Suffix} = lists:split(Position, List).

39
Q

What function reverse an Erlang list?

A

Reversed = lists:reverse(List).

40
Q

How do you define a record in Erlang?

A

-record(name, {
key1 = val1,
key2 = val2,
}).

41
Q

Record keys and values may be of any type in Erlang.

A

False - keys must be atoms.

42
Q

The name of a record must be an atom.

A

True.

43
Q

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,
}).

A

False, val1 & val2 are default values for key1 & key2, respectively.

44
Q

Must a key be given a default value in an Erlang record definition?

A

No.

45
Q

What is the value of R1’s age?
-record(person, {name = unknown, age}).
R1 = #person{}.

A

Age is undefined.

46
Q

Create a record wherein age is defined explicitily, using the definition below.
-record(person, {name = unknown, age}).

A

R1 = #person{age = 99}.

47
Q

Access the “age” field of a “person” record stored in variable R1.

A

Age = R1#person.age.

48
Q

Where are record declarations generally declared?

A

In separate file(s), and then included in the current files.

49
Q

Included files in Erlang are given what extension?

A

.hrl

50
Q

Write the code to import declarations from an external file called “person.hrl”.

A

-include(“person.hrl”).

51
Q

Define the same map using two different syntaxes.

A

M1 = #{man => “joe”, women => “sue”}.
M2 = #{man := “joe”, women := “sue”}.