Basic Sintax Flashcards

1
Q

Return the first occurrence of a pettern

A

Regex.run %r/[aei]/, “aeiou”

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

Replace all occurrences of a pettern with a value

A

Regex.replace %r/[a]/, “aeiou”, “A”

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

Return a list with all occurrences of a pettern

A

Regex.scan %r/[aeiou]/, “caterpillar”

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

How to define an anonymous function?

A

sum = fn (a, b) -> a + b end

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

How to print a simple IO message?

A

IO.puts “Hello World”

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

How to call a anonymous function?

A

sum.(10, 20)

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

How is the sintaxe of The & Notation?

A

add_one = &(&1 + 1)

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

How to define a basic function?

A

defmodule Times do
def double(n) do
n*2
end
end

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

How to define a inline function?

A

def double(n), do: n * 2

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

How to define a Guard Clausule?

A

defmodule Guard do
def what_is(x) when is_number(x) do
IO.puts “#{x} is a number”
end
end

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

How to define default params?

A

defmodule Example do
def func(p1, p2 // 2, p3 // 3, p4) do
IO.inspect [p1, p2, p3, p4]
end
end

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

How to create a alias to a module?

A

defmodule Example do
def func do
alias My.ModuleFoo, as: Foo
doc = Foo.setup
end
end

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

How to define a module attribute?

A

defmodule Example do
@author “User Name”
end

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

How to implement a list comprehension?

A

lc x inlist [1,2,3], do: x * 2

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

How to access a index of a String?

A

String.at(“123”, 2)

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

How to get the length of a String?

A

String.length(“my_String”)

17
Q

How to replace a part of aString?

A

String.replace(“string”, “s”, “S”)

18
Q

How to define a Record?

A

defrecord Phone, country: “1”, area: “555”, local: nil

19
Q

How to instantiate a Record?

A

Phone.new local: “1212”

20
Q

How to set a Record attribute?

A

record.attribute_name “value”