1.
Which of the following is NOT true?
Correct Answer
D. An expression can contain statements.
Explanation
An expression is a combination of variables, operators, and constants that evaluates to a value. It is a single unit that can be evaluated. On the other hand, a statement is a complete instruction that performs an action. It can include expressions, but it cannot contain other statements. Therefore, the statement "An expression can contain statements" is not true.
2.
Scripting languages, by definition, require which of the following:
Correct Answer
C. A host environment
Explanation
Scripting languages, such as JavaScript or Python, require a host environment to execute their code. This host environment provides the necessary resources and infrastructure for the scripting language to run. It includes components like a compiler or interpreter, libraries, and runtime environment. Without a host environment, the scripting language would not be able to execute its code properly. Therefore, a host environment is a requirement for scripting languages to function correctly.
3.
IO in purely functional programming languages is typically accomplished through the use of
Correct Answer
A. Monads
Explanation
In purely functional programming languages, IO (Input/Output) operations are typically accomplished through the use of monads. Monads provide a way to encapsulate impure operations, such as reading from or writing to the console or files, within a pure functional context. By using monads, the effects of IO operations can be managed and controlled, ensuring that the overall program remains pure and free from side effects. Monads also enable composition of IO operations, allowing for more complex IO workflows to be expressed in a clear and concise manner.
4.
The defining characteristic of a closure is the presence of a(n)
Correct Answer
C. Bound variable
Explanation
A closure is a function that has access to variables from its outer scope, even after the outer function has finished executing. The defining characteristic of a closure is the presence of a bound variable, which is a variable that is declared in the outer function and is still accessible in the inner function. This bound variable is "bound" to the inner function, allowing it to be used even when the outer function is no longer in scope.
5.
Algebraic Data Types are
Correct Answer
B. Tagged unions
Explanation
Algebraic Data Types refer to a concept in programming languages where a type can have multiple possible values, each of which is defined by combining other types. Tagged unions, also known as sum types, are a specific implementation of Algebraic Data Types where a value can be one of several different types, and each possible type is tagged with a label. This allows for more expressive and flexible data structures, as they can represent a variety of different cases or states.
6.
The "yield" keyword in Icon, XL, Ruby, Python 2.0, C# 2.0, and JavaScript 1.7 results in which of the following?
Correct Answer
A. The use of a generator
Explanation
The "yield" keyword in programming languages such as Icon, XL, Ruby, Python 2.0, C# 2.0, and JavaScript 1.7 is used for the creation of a generator. A generator is a special type of function that can pause its execution and resume it later, allowing for the generation of a sequence of values. When the "yield" keyword is encountered, the current state of the function is saved, and the yielded value is returned. The function can then be resumed from where it left off, allowing for the generation of the next value in the sequence. This makes it useful for tasks such as iterating over large datasets or generating infinite sequences.
7.
A first-class function is a
Correct Answer
C. Function that is an object
Explanation
A first-class function is considered to be an object because it can be assigned to a variable, passed as an argument to other functions, and returned as a value from other functions. In programming, objects typically have properties and methods, and a first-class function can have properties and methods just like any other object. This allows for greater flexibility and functionality in the code, as the first-class function can be manipulated and used in various ways.
8.
Between which two generations of programming languages is there no difference in run-time efficiency.
Correct Answer
A. First & second
Explanation
The first and second generations of programming languages have no difference in run-time efficiency. This is because both generations relied on low-level programming languages like machine code and assembly language, which directly interact with the hardware. These languages allow for efficient execution of instructions, as they provide direct control over the computer's resources. In contrast, higher-level languages introduced in later generations focused more on productivity and ease of use, sacrificing some runtime efficiency. Therefore, the first and second generations share the same level of run-time efficiency.
9.
Which of the following programming language families mandates a dynamic type system:
Correct Answer
D. None of the above
Explanation
The given question asks which programming language family mandates a dynamic type system. The options provided are Scripting Languages, Functional Programming Languages, Declarative Programming Languages, and None of the above. The correct answer is "None of the above" because none of the mentioned programming language families specifically mandate a dynamic type system. While scripting languages and some functional programming languages may commonly use dynamic type systems, it is not a requirement for all languages within these families. Similarly, declarative programming languages can use either dynamic or static type systems depending on the specific language implementation.
10.
In Java, JavaScript, Python, and C# what is the result of executing the following pseudo code (translated into each languages respective syntax):try throw exception1finally throw exception2
Correct Answer
B. Exception1 is discarded and exception2 is thrown instead.
Explanation
The given pseudo code uses a try-finally block, which guarantees that the code in the finally block will always be executed, regardless of whether an exception is thrown or not. In this case, exception1 is thrown within the try block, but since there is a finally block, it will still be executed. However, when the finally block is executed, it throws exception2, which replaces exception1. Therefore, exception1 is discarded and exception2 is thrown instead.