Final Questions Flashcards
Describe the concept of ‘Referential Transparency’
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.
Describe the concept of ‘Short-circuit Evaluation’
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.
What is a Mixed-mode Expression?
An expression that contains operands of different types. For example: 1 + 41.0 is a mixed-mode expression.
Describe the concept of Closure of a function
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.
What is a compound assignment operator?
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.
What is operator precedence, and why is it important?
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.
What is the difference between Procedures, Functions and Methods?
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.
What is a parallel assignment operator?
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.
What is the difference between formal parameters, actual parameters, and arguments.
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.
What is a pure function?
A pure function is a function with no side effects.
Describe the concepts of overflow or underflow.
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.
Describe overloading.
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.
Describe conditional assignment statements.
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;
Select all that apply to the SML programming language.
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.
Name a few of the different issues that play a role in the design of programming languages
Problem Domain, Programming philosophy/paradigm, Computer Architecture, Implementation.