Composing Programs One Flashcards

1
Q

What do we need to define a computational process?

A

A programming language.

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

What are 2 uses of a programming language?

A

A means for instructing computers to perform tasks and a framework in which we organise ideas about computational processes.

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

What are 3 mechanisms a programming language has for combining simple ideas to form more complex ones?

A

Primitive expressions/statements, means of combination(building) and means of abstraction(naming).

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

What are two kinds of elements we deal with in programming?

A

Functions and data.

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

Informally, what is data?

A

Stuff we want to manipulate.

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

Informally, what does a function do?

A

They describe the rules for manipulating data.

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

Name a primitive expression.

A

Number

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

Describe infix notation in an expression.

A

The operator appears between the operands.

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

What is the most important type of compound expression?

A

A call expression, which applies a function to some arguments.

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

What are three reasons function notation is better than infix notation?

A

Functions can take an arbitrary number of arguments, for ambiguity can arise because the function name always precedes its arguments. Function expression extends in a straightforward way to nested expressions. Some of the notation can be difficult to type.

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

What comprises the Python library?

A

Modules.

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

What is in a module?

A

Functions and other quanitities.

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

If a value has been given to a name, what do we say about the relation to the value and the name?

A

We say the name binds to the value.

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

How we do establish new bindings?

A

With the assignment statement (=).

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

Name another way names are bound.

A

With the import statement.

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

What is assignment an example of?

A

Abstraction, for it allows us to use simple names to refer to the results of compound operations

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

What is an environment?

A

A memory that keeps track of names, values and bindings.

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

What is another name for names in Python?

A

Variables, because they can be bound to different values in the course of executing a program.

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

What is the interpreter doing when it evaluates nested call expressions?

A

Following a procedure

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

Name the two steps Python does to evaluate a call expression? And what is this procedures nature?

A
  1. Evaluate the operator and operand subexpressions, then
  2. apply the function that is the value of the operator subexpression to the arguments that are the values of the operand subexpressions.

Recursive

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

What are the objects at each point in a tree called?

A

Nodes

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

What direction do trees grow from?

A

The top down

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

What is the complete, full expression at the top of a tree called?

A

Root

24
Q

What do we have to do before we evaluate the root in a tree?

A

We evaluate the subexpressions

25
Q

What are leaf expressions?

A

nodes with no branches stemming from them.

26
Q

What are the two parts of interior nodes?

A

the call expression to which our evaluation rule is applied and the result of that expression.

27
Q

What are two different types of functions?

A

Pure and non-pure

28
Q

What are the two properties of a pure function?

A

Applying them has no effects beyond returning a value. A pure function must always return the same value when called twice with the same arguments

29
Q

What is the property of a non pure function?

A

A non-pure function can generate side effects, which make some change to the state of the interpreter or computer.

30
Q

What are the advantages of pure functions?

A

They can be composed more reliably into compound expressions.
They can be simpler to test as they always return the same value.

31
Q

How do you define a function?

A

Function definitions consist of a def statement that indicates a <name> and a comm separated list of <formal> then a return statement called the function body that specifies the <return> of the function.</return></formal></name>

32
Q

What does an environment consist of? (in detail)

A

A sequence of frames

33
Q

What does a frame contain?

A

Bindings

34
Q

How many global frames are there?

A

A single global frame

35
Q

What is the name (for a function) appearing in the function ?

A

Intrinsic name

36
Q

What is the name (for a function) appearing in the frame?

A

Bound name

37
Q

Does the intrinsic name for a function play a role in evaluating a function?

A

No

38
Q

What does applying a user-defined function introduce?

A

A local frame

39
Q

What are the two steps in applying a user defined function?

A

Bind the arguments to the names of the function’s formal parameters in a new local frame.
Execute the body of the function in the environment that starts with this frame.

40
Q

What is name evaluation?

A

A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.

41
Q

How many jobs should a function have?

A

One

42
Q

What is the DRY principle?

A

Dont repeat yourself. Logic should be implemented once, given a name, and applied multiple times.

43
Q

How to provide default argument values?

A

Write argument = x in the def line of the function.

44
Q

What does control statements allow us to do?

A

Make comparisons and perform different operations based on the results of comparisons. They are statements that control the flow of a program’s execution based on the results of logical comparisons.

45
Q

Why are statements different from expressions?

A

Statements differ fundamentally from the expressions that we have studied so far. They have no value. Instead of computing something, executing a control statement determines what the interpreter should do next.

46
Q

Are statements or expressions evaluated or executed?

A

Statements are executed and expressions are evaluated

47
Q

What is the role of statements?

A

Statements govern the relationship among different expressions in a program and what happens to their results.

48
Q

What is Python code, simply?

A

A sequence of statements?

49
Q

What is a simple statement?

A

A line of code that doesnt end in a colon.

50
Q

Why is it called a compound statement?

A

Because it is composed of simple and compound statements. Compound statements typically span multiple lines and start with a one-line header ending in a colon, which identifies the type of statement

51
Q

What is a clause?

A

Together, a header and an indented suite of statements is called a clause. A compound statement consists of one or more clauses

52
Q

How do we recursively understand multi-line programs?

A

To execute a sequence of statements, execute the first statement. If that statement does not redirect control, then proceed to execute the rest of the sequence of statements, if any remain

53
Q

What is the essential structure of a recursively defined sequence?

A

a sequence can be decomposed into its first element and the rest of its elements. The “rest” of a sequence of statements is itself a sequence of statements! Thus, we can recursively apply this execution rule.

54
Q

WHat does a conditional statement in Python consist of?

A

conditional statement in Python consists of a series of headers and suites: a required if clause, an optional sequence of elif clauses, and finally an optional else clause

55
Q

What is the computational process of executing a conditional clause?

A

The computational process of executing a conditional clause follows.

Evaluate the header’s expression.
If it is a true value, execute the suite. Then, skip over all subsequent clauses in the conditional statement.

56
Q

What is an expression in boolean context?

A

The expressions inside the header statements of conditional blocks are said to be in boolean contexts: their truth values matter to control flow, but otherwise their values are not assigned or returned.