Final Questions Flashcards

1
Q

Describe the concept of ‘Referential Transparency’

A

An expression is said to be referentially transparent, if it can be substituted for the value it evaluates to, without changing the behavior of the program. Expressions with side-effects are not referentially transparent.

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

Describe the concept of ‘Short-circuit Evaluation’

A

Short-circuit evaluation is a form of lazy-evaluation in which given a binary boolean expression, the second (right-hand side) argument is evaluated only if the evaluation of the first (right-hand side) argument does not suffice to determine the overall value of the expression. For example, in the expression ‘b1 and b2’, b2 is evaluated only if b1 is true, as otherwise the expression would be known to be false regardless of the value of b2.

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

What is a Mixed-mode Expression?

A

An expression that contains operands of different types. For example: 1 + 41.0 is a mixed-mode expression.

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

Describe the concept of Closure of a function

A

A function closure is programming device that includes a function definition along with an environment that includes bindings for some (or all) of the free variables in said function. In other words, it is a partially evaluated function. For example:

fun add x y = x + y;
plusOne = add 1;
plusOne 3;
val it = 4 : int;

in the code above plusOne is a partially evaluated version of add that includes an environment in which x is bound to 1.

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

What is a compound assignment operator?

A

A compound assignment operator is one that serves as an abbreviation of performing an operation on a variable and assigning the result to the same variable. For example, if one were to add a value to a variable and the assign the result to the same variable: x = x + 42, then this could be be abbreviated using an addition compound assignment as: x += 42.

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

What is operator precedence, and why is it important?

A

Operator precedence refers to binding priority established between the different operators in a language and their arguments. For example, if * has precedence over +, then the expression 3 * 7 + 21 is interpreted as (3 * 7) + 21 instead of 3 * (7 + 21), because the 7 binds with the * before it binds with the +. Operator precedence is used to solved semantic ambiguities while parsing expressions in programs.

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

What is the difference between Procedures, Functions and Methods?

A

A procedure (or sub-routine), in the strictest of senses, is a sub-task, a sequence of instructions, that may be invoked throughout the program. A function, on the other hand, takes an (optional) input and produces an output. A method, on the other hand, is a concept from OO programming where the execution of a function is associated with a target object: side-effects, if any, are contained to that object as the method is seen as an agent of mediation between the rest of the program and the object. In modern parlance, the distinction between procedure and function has been blurred, but the distinction between function/procedure and method is very punctuated.

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

What is a parallel assignment operator?

A

A feature by which multiple variables are assigned values in a single statement. For example: int a, b, c := 1, 2, 3; – in this case a is assigned 1, b is assigned 2, and c is assigned 3.

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

What is the difference between formal parameters, actual parameters, and arguments.

A

Formal parameters are the names given to the inputs to a function, used in the body of the function to access those inputs. Arguments are the values bound to the formal parameters after a function call. For example, if a function is declared as int f(int x); and called with f(42); then the formal parameter is x and the argument is 42. If the function is passed a variable name such as f(y); then y is sometimes known as the actual parameter, though this is sometimes also used to refer to arguments in general.

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

What is a pure function?

A

A pure function is a function with no side effects.

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

Describe the concepts of overflow or underflow.

A

The result of an arithmetic operation that results in a value that exceeds the storage capacity (greatest possible value for overflow, least possible value for underflow). For example, for a signed 32 bit integer 2^31 + 1, or -2^31 - 1.

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

Describe overloading.

A

When a function or operator is given multiple behaviors depending on the arguments/operands. For example, in Java + performs addition if the operands are integers, or concatenation if the operands are strings.

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

Describe conditional assignment statements.

A

An assignment operator in which the value assigned depends on a given condition. For example, in Java, this is achieved using the ternary operator int x = cond ? 42 : 0;

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

Select all that apply to the SML programming language.

A

a. Everything is a function.
b. Interpreted.
c. Supports concurrent
programming.
d. Dynamically Typed.
e. Functions are allowed to
have side-effects.
f. Garbage Collected.
g. Polymorphic.
h. All recursive functions are
optimized into loops.
i. SML supports
polymorphism,encapsulation,
and information hiding.
Therefore, SML is Object-
Oriented.

Answers: e, f, g.

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

Name a few of the different issues that play a role in the design of programming languages

A

Problem Domain, Programming philosophy/paradigm, Computer Architecture, Implementation.

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

Name 3 of the most important programming paradigms

A

Imperative/procedural, Functional/declarative/applicative, Logical/constraint-based (Object-oriented).

17
Q

Name the main evaluation criteria for programming language design

A
Simplicity
Orthogonality
Level of abstraction
Portability
Cost
Expressivity
18
Q

How is criteria of Simplicity applied to programming language design?

A

The language feature set should be minimal, with rules on how to apply them and combine them as simple and clear as possible.

19
Q

How is criteria of Orthoganility applied to programming language design?

A

Primitives can be combined in relatively small number of ways, and every combination is legal and meaningful.

20
Q

How is criteria of Abstraction applied to programming language design?

A

The language provides mechanisms to define powerful data abstractions that approximate constructs in the problem domain.

21
Q

How is criteria of Portability applied to programming language design?

A

Programs written in the language can be moved from the system they were created to other systems with relative ease.

22
Q

How is criteria of Cost applied to programming language design?

A

The cost of using the language (development, compilation, maintenance, execution, etc.) is manageable.

23
Q

How is criteria of Expressivity applied to programming language design?

A

The language provides concise, different ways of defining algorithms and computations.

24
Q

Give an example of a pair of evaluation criteria that are in tension with each other, and explain why

A

Simplicity vs. Expressivity: If a language is simple it means it provides a limited set of primitive constructs, and limited, clear rules for how to combine them, which means that there are relatively few ways to define the same computation in concise ways, hurting the expressive power of the language.

25
Q

What are the main technologies used to implement programming languages?

A

Compilers
Interpreters
Virtual Machines

26
Q

What are Reserved Words in Programming Languages?

A

These are especial words that cannot be used as names (variables, functions, etc.) in the program, since they are used for other purposes in the language (names of primitive constructs, keywords, etc.).

27
Q

Describe the terms L-value and R-value of a variable

A

The L-value is the memory address of a variable, and the R-value is the value stores in that memory address.

28
Q

Describe the term Aliasing in reference to variables

A

Aliasing refers to the situation when a single memory address has more than one name, in other words, two or more variables share the same L-value.

29
Q

What is the difference between static and dynamic typing?

A

In static typing the type of a variable is determined statically, that is, before the program is executed, either by syntactic features like a type declaration, or special variable names, or during compilation like type inference. On the other hand, with dynamic typing, the type of a variable cannot be determined until the program is executed and a value is assigned to the variable.

30
Q

What are the differences between unary, binary and ternary operators.

A

Unary operators only need one operand to function (such as i++), binary needs two operands to function (such as 8/2), and ternary operators (also called conditional operators) need three operands to function (condition?expression1:expression2;)

31
Q

Difference between infix and prefix operators?

A

Infix operators go between the operands (A+B), prefix operators go before the operands (+AB).

32
Q

What are operation side effects?

A

In programming a side effect is when a procedure changes a variable from outside its scope.

33
Q

What is short circuiting?

A

It’s the semantics of some Boolean operators in some programming languages in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression: when the first argument of the AND function evaluates to false, the overall value must be false; and when the first argument of the OR function evaluates to true, the overall value must be true.

34
Q

What is a subprogram call?

A

A subprogram call is either a procedure_call_statement or a function_call; it invokes the execution of the subprogram_body.

35
Q

Difference between methods and functions?

A

Functions are defined in structural language and methods are defined in object oriented languages.

36
Q

What is a parameter profile?

A

A subprogram header contains a list of formal parameters. The parameter profile of a subprogram contains information about its formal parameters. The information contains number, type, and order of formal parameters.

Ex. header “void fun(int a, float b, char c);

Here the information inside the parenthesis is parameter profile. The parameter profile of the subprogram fun() tells that there are 3 parameters which are of type int, float, and char in the specified order.

37
Q

Parameter passing vs non local variables

A

If the variable has a local declaration (that is, it is a local variable or parameter), the compiler will use the local variable or parameter, even if a non-local variable (static variable or instance variable) with the same name exists. Local variables, therefore, take precedence over non-local variables.

38
Q

Difference between formal parameters vs actual parameters.

A

The term parameter (sometimes called formal parameter) is often used to refer to the variable as found in the function definition, while argument (sometimes called actual parameter) refers to the actual input supplied at function call