Sample Questions: SICP Section 1.1
Revision date: 22 August

The Elements of Programming

Concept: programming languages

  1. A dynamically-typed language has the following property:
    1. variables are declared with a type
    2. once set, variables cannot change their values
    3. once declared, variables cannot change their types
    4. variable types are declared without a type
  1. A functional programming language is characterized by:
    1. the lack of assignment (and other side effects)
    2. the lack of static typing
    3. the ability to define classes
    4. the ability to define functions
  1. The three hallmarks of an object-oriented language are:
    1. encapsulation, inheritance, polymorphism
    2. structures, objects, and modules
    3. objects, loops, and functions
    4. inheritance, modules, and interpretation
  1. An imperative language is characterized by:
    1. conditionals
    2. recursion
    3. functions
    4. side-effects
  1. T or F: Purely functional languages are considered side-effect free.
  1. T or F: A language can be side-effect free and provide for assignment.

Concept: expressions

  1. Which of the following is not a primitive expression?
    1. an integer
    2. a variable
    3. a real number
    4. a string
  1. The simplest abstraction of a primitive expression is:
    1. a variable
    2. a procedure
    3. a number
    4. a compound expression
  1. Abstractions are made in Scheme using the keyword:
    1. abstract
    2. include
    3. define
    4. var
  1. In Scheme, the order in which the operator and operands of an expression are evaluated is:
    1. from left to right
    2. the operator first, the operands unspecified
    3. unspecified
    4. the operator last, the operands unspecified
    5. from right to left
    6. the operator first, the operands from right to left
  1. T or F: A compound expression is a combination of primitive and/or compound expressions.
  1. T or F: With regards to Scheme, statements and expressions are equivalent.
  1. T or F: In Scheme, a compound expression must involve at least one function call.
  1. A primitive function is:
    1. a function that is 'wrapped' by another function
    2. a predefined function
    3. a simple one-line function
    4. a function that performs arithmetic operations
  1. T or F: In Scheme, operators are considered distinct from functions.
  1. T or F: Scheme operators have precedence (e.g. multiplications are performed before additions).
  1. T or F: Scheme operators have associativity.
  1. If 5 - 2 - 1 is 4, then the associativity of the subtraction operator is:
    1. inward associative
    2. outward associative
    3. left associative
    4. right associative
  1. Scheme uses:
    1. postfix notation
    2. prefix notation
    3. level-order notation
    4. infix notation
    5. prefix notation for functions, infix for expressions
  1. Unlike SICP, the world of programming languages sometimes makes a distinction between procedures and functions. What is this distinction?
    1. functions generally depend on side-effects to perform their task
    2. the return value of a function (if any) is generally ignored
    3. the return value of a procedure (if any) is generally ignored
    4. functions encapsulate a series of steps to take rather than compute values
  1. A variadic function is:
    1. a function that contains a conditional
    2. a function that can take a variable number of arguments
    3. a function that defines local variables
    4. a function that returns various values given the same arguments.

Concept: names and environments

  1. Which of the following is an example of a variable definition in Scheme?
    1. (= (x) 1)
    2. (define x 1)
    3. int x = 1;
    4. (def x = 1)
  1. A Scheme environment is:
    1. an IDE written in Scheme
    2. the arguments to a function call
    3. an IDE for programming in Scheme
    4. a repository of variables and their values
  1. T or F: Syntactically speaking, any where a primitive value can be used in Scheme, a variable can be used.
  1. T or F: Syntactically speaking, any where a variable can be used in Scheme, the primitive value can be used.
  1. T or F: Variable definition is a form of abstraction.
  1. T or F: Abstraction allows the programmer to focus on the details of a computational object.

Concept: evaluating combinations

  1. T or F: In Scheme, it is possible for a compound expression to be a subexpression of a compound expression.
  1. T or F: In Scheme, the symbol + is a variable.
  1. T or F: In Scheme, the symbol + can be redefined.
  1. Evaluating a variable in an expression in functional Scheme yields:
    1. the variable value
    2. the variable location in the source code
    3. the variable location in memory
    4. the variable name
  1. Evaluating a numeral in functional Scheme yields:
    1. a symbol
    2. the variable that has that value
    3. the corresponding number
    4. you can't evaluate a numeral; it is in its simplest form
  1. When the expression (+ a b) is evaluated, which subexpression is evaluated first?
    1. a
    2. +
    3. b
    4. unknown (implementation dependent)

Concept: compound functions

  1. What is wrong with the following Scheme function definition?
        (def (square x) (* x x))
    
    1. nothing, the function is syntactally correct
    2. there is no return statement
    3. the formal parameters are not in a list
    4. the keyword is define, not def
  1. What is wrong with the following Scheme function definition?
        (define square (x) (* x x))
    
    1. there is no return statement
    2. the keyword is def, not define
    3. nothing, the function is syntactally correct
    4. the function name should be grouped with the formal parameters
  1. T or F: Scheme does not have explicit returns.
  1. T or F: Scheme does not have implicit returns.
  1. 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?
    1. undefined, since implicit returns are not allowed
    2. 9 is returned
    3. an infinite resursive loop, when return returns
    4. error, you cannot redefine the keyword return

Concept: substitution models

  1. 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?
    1. 3
    2. 1
    3. 4
    4. 2
  1. 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. 1
    2. 4
    3. 2
    4. 3

Concept: conditionals

  1. T or F: Cond expressions must have a default case.
  1. T or F: Cond expressions must two or more cases.
  1. T or F: The default case in a cond expression is signaled by the symbol else.
  1. T or F: Cond expressions exhibit short-circuiting (i.e., a subsequent case predicate is only evaluated if the previous predicates are false).
  1. T or F: Scheme's and operator exhibits short-circuiting.
  1. T or F: Scheme's or operator exhibits short-circuiting.
  1. T or F: In Scheme, an operator that short-circuits must be a special form.
  1. Using DeMorgan's rules, simplify the following expression:
        (not (or (not (and a b)) (or c (not d))))
    
    1. (or (or (not a) (not b)) (or c (not d)))
    2. (or a b c d)
    3. (and (or a b) (or c d))
    4. (and a b (not c) d)
  1. T or F: In Scheme, a special form is introduced by a keyword.
  1. In Scheme, how would you determine programatically whether or not an and expression is a special form?
    1. attempt to pass the expression to a function
    2. attempt to pass and itself to a function
    3. attempt to nest two and expressions
    4. attempt to return the expression from a function

Concept: Local Names

  1. Which is not an advantage of nesting functions:
    1. more freedom in naming
    2. improved locality
    3. reduced namespace pollution
    4. both local and non-local access
    5. variables in the outer function are accessible to the nested function
  1. 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?
    1. a value of three is retrieved
    2. a scope error occurs
    3. Scheme will not allow this function to be defined

    4. a value of nine is retrieved