Sample Questions: SICP Section 1.1
Revision date: 22 August
The Elements of Programming
Concept: programming languages

A dynamicallytyped language
has the following property:
 variables are declared with a type
 once set, variables cannot change their values
 once declared, variables cannot change their types
 variable types are declared without a type

A functional programming language is characterized by:
 the lack of assignment (and other side effects)
 the lack of static typing
 the ability to define classes
 the ability to define functions

The three hallmarks of an objectoriented language are:
 encapsulation, inheritance, polymorphism
 structures, objects, and modules
 objects, loops, and functions
 inheritance, modules, and interpretation

An imperative language is characterized by:
 conditionals
 recursion
 functions
 sideeffects

T or F:
Purely functional languages are considered sideeffect free.

T or F:
A language can be sideeffect free and provide for assignment.
Concept: expressions

Which of the following is not a primitive expression?
 an integer
 a variable
 a real number
 a string

The simplest abstraction of a primitive expression is:
 a variable
 a procedure
 a number
 a compound expression

Abstractions are made in Scheme using the keyword:

abstract

include

define

var

In Scheme, the order in which the operator and operands of an
expression are evaluated is:
 from left to right
 the operator first, the operands unspecified
 unspecified
 the operator last, the operands unspecified
 from right to left
 the operator first, the operands from right to left

T or F:
A compound expression is a combination of
primitive and/or compound expressions.

T or F:
With regards to Scheme, statements and expressions are equivalent.

T or F:
In Scheme, a compound expression must involve at least one function call.

A primitive function is:
 a function that is 'wrapped' by another function
 a predefined function
 a simple oneline function
 a function that performs arithmetic operations

T or F:
In Scheme, operators are considered distinct from functions.

T or F:
Scheme operators have precedence (e.g. multiplications
are performed before additions).

T or F:
Scheme operators have associativity.

If $521$ is 4, then the associativity of the subtraction
operator is:
 inward associative
 outward associative
 left associative
 right associative

Scheme uses:
 postfix notation
 prefix notation
 levelorder notation
 infix notation
 prefix notation for functions, infix for expressions

Unlike SICP, the world of programming languages sometimes
makes a distinction
between procedures and functions. What is this distinction?
 functions generally depend on sideeffects to perform their task
 the return value of a function (if any) is generally ignored
 the return value of a procedure (if any) is generally ignored
 functions encapsulate a series of steps to take rather than compute values

A variadic function is:
 a function that contains a conditional
 a function that can take a variable number of arguments
 a function that defines local variables
 a function that returns various values given the same arguments.
Concept: names and environments

Which of the following is an example of a variable definition in Scheme?
 (= (x) 1)
 (define x 1)
 int x = 1;
 (def x = 1)

A Scheme environment is:
 an IDE written in Scheme
 the arguments to a function call
 an IDE for programming in Scheme
 a repository of variables and their values

T or F:
Syntactically speaking,
any where a primitive value can be used in Scheme, a variable can be used.

T or F:
Syntactically speaking,
any where a variable can be used in Scheme, the primitive value can be used.

T or F:
Variable definition is a form of abstraction.

T or F:
Abstraction allows the programmer to focus on the details of a
computational object.
Concept: evaluating combinations

T or F:
In Scheme,
it is possible for a compound expression to be a subexpression of a compound
expression.

T or F:
In Scheme, the symbol
+
is a variable.

T or F:
In Scheme, the symbol
+
can be redefined.

Evaluating a variable in an expression in functional Scheme yields:
 the variable value
 the variable location in the source code
 the variable location in memory
 the variable name

Evaluating a numeral in functional Scheme yields:
 a symbol
 the variable that has that value
 the corresponding number
 you can't evaluate a numeral; it is in its simplest form

When the expression
(+ a b)
is evaluated, which subexpression
is evaluated first?
 a
 +
 b
 unknown (implementation dependent)
Concept: compound functions

What is wrong with the following Scheme function definition?
(def (square x) (* x x))
 nothing, the function is syntactally correct
 there is no return statement
 the formal parameters are not in a list
 the keyword is
define
, not
def

What is wrong with the following Scheme function definition?
(define square (x) (* x x))
 there is no return statement
 the keyword is
def
, not
define
 nothing, the function is syntactally correct
 the function name should be grouped with the formal parameters

T or F: Scheme does not have explicit returns.

T or F: Scheme does not have implicit returns.

In Scheme, suppose one attempted to define a function named return which
implicitly returns its argument:
(define (return x) x)
Suppose further that the body of the
square function was written as:
(return (* x x))
What would happen if
(square 3)
is evaluated?
 undefined, since implicit returns are not allowed
 9 is returned
 an infinite resursive loop, when return returns
 error, you cannot redefine the keyword
return
Concept: substitution models

Given the definitions of square as found in the text,
how many multiplications are performed if the following expression:
(square (square 3))
is evaluated using applicative order?
 3
 1
 4
 2

Given the definitions of square as found in the text,
how many multiplications are performed if the following expression:
(square (square 3))
is evaluated using normal order?
 1
 4
 2
 3
Concept: conditionals

T or F: Cond expressions must have a default case.

T or F: Cond expressions must two or more cases.

T or F:
The default case in a cond expression is signaled by the symbol
else
.

T or F:
Cond expressions exhibit shortcircuiting
(i.e., a subsequent case predicate
is only evaluated if the previous predicates are false).

T or F:
Scheme's and operator exhibits shortcircuiting.

T or F:
Scheme's or operator exhibits shortcircuiting.

T or F:
In Scheme, an operator that shortcircuits must be a special form.

Using DeMorgan's rules, simplify the following expression:
(not (or (not (and a b)) (or c (not d))))
 (or (or (not a) (not b)) (or c (not d)))
 (or a b c d)
 (and (or a b) (or c d))
 (and a b (not c) d)

T or F:
In Scheme, a special form is introduced by a keyword.

In Scheme, how would you determine programatically
whether or not an
and
expression
is a special form?
 attempt to pass the expression to a function
 attempt to pass
and
itself to a function
 attempt to nest two
and
expressions
 attempt to return the expression from a function
Concept: Local Names

Which is not an advantage of nesting functions:
 more freedom in naming
 improved locality
 reduced namespace pollution
 both local and nonlocal access
 variables in the outer function are accessible to the nested function

Consider the println expression in the nested function:
(define (f x)
(define (g y)
(println (+ x y))
)
(g (* x x))
)
with an initial call of
(f 3)
.
What happens when the x in the println is accessed?
 a value of three is retrieved
 a scope error occurs
 Scheme will not allow this function to be defined
 a value of nine is retrieved