CS 331 Spring 2025 > Exam Review Problems, Set E
CS 331 Spring 2025
Exam Review Problems, Set E
This is the fifth set of exam review problems.
Problems
Review problems are given below. Answers are in the Answers section of this document. Do not turn these in.
Answers
- In Scheme, we can place a dot just before the last item
in what would otherwise be a list with at least two items.
For example, we can write
“
(1 2 3 . 4)
” - The Scheme list
(1 2 3)
can also be written as(1 . (2 . (3 . ())))
. - Your instructor says, “Dot is not a procedure.”
This is true because dot is not a procedure.
It is important because it means that the arguments of dot are
not evaluated as one would expect if it were a procedure.
For example,
“
((car x) . (car y))
” might be expected to construct a pair whose first item is thecar
ofx
and whose second item is thecar
ofy
. However, since dot is not a procedure, this is actually just another way of writing the three-item list “((car x) car y)
”.
- In Scheme, we can place a dot just before the last item
in what would otherwise be a list with at least two items.
For example, we can write
“
- Below is the Scheme value
(() . 1) . 2)
- The standard Scheme numeric equality procedure is
=
. - Scheme has no standard numeric inequality procedure.
- Your instructor recommends checking equality of non-numeric values
in Scheme using procedure
equal?
.
- The standard Scheme numeric equality procedure is
- A Scheme macro is a specified code transformation that is known to the Scheme implementation.
- A pattern-based macro is a macro in which one or more patterns are given; code that matches a pattern is transformed as indicated.
- A hygienic macro is one that limits interaction between identifiers inside the macro and those outside—in much the same way that such interactions can be limited in procedures, using local variables.
- In the context of Scheme macros, a keyword is a word in a pattern that matches only itself.
- The
else
that can be used as the last condition in a Schemecond
construction is an example of a Scheme macro keyword.
- Static semantics refers to issues of meaning that are handled before a program runs.
- One issue that involves static semantics is determination and checking of types in a programming language that has static typing: C, C++, Java, Haskell, etc. Other answers are possible.
- In the C++ Standard, the semantics of C++ is specified entirely informally.
- A tree-walk interpreter is an interpreter that processes an AST and executes it directly, without creating any other intermediate representation.
- Tree-walk interpreters are not used very often because they have poor performance.
- This form of code is called a byte code.
- A program that executes byte code directly is usually called a virtual machine.
- A JIT compiler is given byte code. This is split into multiple sections, each of which is executed as appropriate by a virtual machine. Between these executions, one or more of the sections may be compiled to machine language. In the future, if such a section needs to be executed, it can simply be called like a function; the virtual machine is not necessary.
- Huh? What? Because it’s faster! (Did I get it right?)
- Profile-based optimizations are optimizations based on information about what portions of code spend the most time executing.
- Higher-temperature ratings indicate that fast execution is a higher priority for a code section. A hotter code section is more likely to be compiled, more likely to be aggressively optimized, and more likely to be re-compiled with more optimization.
- The state of a program includes all information
about the current situtation of a running program.
This includes all of the following.
- The current execution location.
- The values of all variables.
- The call stack.
- In a programming language with static typing and scope, variables are typically laid out in memory—static space or the call stack. There is a location for each variable; its value is stored there.
- In a dynamic programming language, values of variables are typically stored in an associative structure, usually a hash table. The variable name is the key; the associated value is the variable’s value.
- The code that aids in the execution of a program is called the runtime system, or simply the runtime.
- Since our programming language has no fatal runtime errors, undefined variables and functions have a specified default value. And computations that would normally have no numeric value—for example, division by zero—have a specified numeric value.
- To unify two constructions is to make them the same by binding variables as necessary.
- We can unify [X, 4] and [1, Y] by setting X = 1 and Y = 4.
- In logic programming, we are not so much interested in whether something is true or false, as we are in whether it is provable.
- This emphasis on provability means that negation is about something not being provable—as opposed to not being true.
- The primary strategry for proving something in Prolog is to attempt to unify it with something known to be true.
- A Prolog predicate is something we might prove to be true.
- The name of a Prolog predicate is always a Prolog atom.
- True. In Prolog, lists and numeric expressions are both examples of compound terms.
- False. A Prolog program is made of facts and rules, but not queries.
- A Prolog fact says that something is true.
- A Prolog rule says that something is true if other things can be proven. It is a way of deriving new known things from other known things.
- Every Prolog fact or rule ends with a dot (
.
). - Every Prolog rule contains the character sequence
“
:-
”.