Chapter 7 Flashcards

1
Q

What are expressions?

A

Fundamental means of specifying computations in a programming language

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

What is needed to understand expression evaluation?

A

The orders of operator and operand evaluation

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

What do arithmetic expressions consist of?

A

Operators
Operands
Parentheses
Function calls

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

What are some design issues with Arithmetic expressions?

A

Operator precedence rules
Operator associativity rules
Order of operand evaluation
Are operand evaluation side effects restricted
Is user-defined operator overloading allowed?
What type mixing is allowed

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

How many operators does a Unary/Binary/Ternary operand have?

A

Unary = 1
Binary = 2
Ternary = 3

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

Typical precedence levels of a language

A

Parentheses. Unary operators. ** or ^. * and /. + and -

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

Operator associativity rules

A

Define order in which adjacent operators with the same precedence level are evaluated

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

Typical associativity rules

A

Left to right (** = right to left)

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

How are operators implemented in Ruby?

A

As methods
(Arith, relational, assignment)

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

Can you overwrite operators in Ruby?

A

Yes because they are methods

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

Scheme and Common LISP arithmetic and logic operations are implemented as?

A

Explicitly called subprograms

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

Operand Evaluation Order

A

Variables, Constants, Parenthesized expressions

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

Problematic operator overloading

A

& in C and C++. Loss of readability and loss of compiler error detection

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

Can user-defined overloaded operators increase readability?

A

Yes but only when sensibly used (+)

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

What is narrowing conversions in Type Conversions

A

Converts an object to a type that cannot include all of the values of the origin type (float to int)

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

What is widening conversion in Type Conversions

A

Converts an object to a type including at least approximations of all the original type’s values. May lose accuracy (int to float)

17
Q

What is Mixed-mode expression?

A

Expression that has operands of different types. ( a is int, b is float. a + b = mixed mode)

18
Q

What is Coercion in Type Conversions?

A

The auto type conversion of operands. Decreases compiler’s type error detection ability.

19
Q

What is explicit type conversion?

A

Programmer-specified type conversions. Can be either narrowing or widening? Compiler may give warnings. ( (int) in C languages)

20
Q

What causes errors in expressions with type conversions?

A

Type checking and coercion.
Limitations of arithmetic, Inherent and computer.
Run time errors can be ignored but may require exception handling mechanisms

21
Q

What do relational expressions evaluate to?

A

Booleans

22
Q

What does short circuit evaluation do?

A

Doesnt evaluate all operands and operators (13a)(b) if a = 0 b isnt evaluated

23
Q

When can short circuit evaluation be a problem?

A

When there are side effects in expressions.

24
Q

What is the problem with = overloading

A

There is ambiguity between assignment and equality

25
Q

What are conditional targets?

A

Similar to conditional expressions ($flag ? $total : $subtotal

26
Q

How does a compound assignment operator look like?

A

A += B

27
Q

Can assignments also be mixed-mode?

A

Yes