CSC 8310 -- Final Exam
Section 001: Tuesday & Thursday 4:30 to 5:45pm in Mendel G30
Section 002: Thursday 6:15 to 8:45 in Mendel G30
Spring 2000, Villanova University

  1. Consider the following BNF:
        <digit>  ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
        <unary>  ::= + | -
        <binary> ::= * | /
        <unit>   ::= <digit> | <unit> <unary> | <unit> <binary> <unit>

    (4 points) Which of the following things are valid <unit>s? Write "yes" for each valid <unit>, "no" for each expression that is not a <unit>.
     

    1. 2 * 3 - * 4
       
    2. 2 3 + 4 -
       
    3. 1 - / 2 + / 3
       
    4. 2 - * 3 / 4 + / 5

    (2 points) Write a valid unit that is exactly eight symbols long.


     

  2. (3 points) How are parameters passed? (Fill in the blanks.)
    1. In Java, objects are passed by __________.
    2. In Prolog, parameter transmission is by __________.
    3. In Haskell, parameter transmission is by __________.
       
  3. (8 points) Briefly, distinguish among the following four terms: 
     
  4.  

  5. (4 points) Briefly, what is meant by each of the following two terms: 
     
  6. (5 points) In most languages, storage for the values of variables can be allocated either on the stack or on the heap.
     
    1. When is storage allocated on the stack? That is, what does the program do that causes the stack to expand?
       
       
    2. When is storage allocated on the heap instead of the stack?
       
       
    3. When a "memory leak" occurs, did the lost storage come from the heap or from the stack?
       
       
  7. (4 points) We discussed two garbage collection algorithms. Name them and give one disadvantage of each.
     
     
     
     
     
     
  8. (6 points) The Design Pattern you used in the Magic Forest animated applet was the MVC pattern. Briefly name each of the three parts (M, V, and C) and tell what their responsibilities are. 
     
  9. (6 points) Briefly define each of the following terms:
     
  10. (8 points) Unification is an essential operation in Prolog. For each of the following, tell (1) whether the two expressions can be unified, and (2) if so, what values are given to each of the variables.
     
    1. f(X, Y) = g(5, 7)
       
       
    2. mother(john, Dick) = mother(Jack, richard)
       
       
    3. mother(tom, Dick) = mother(Dick, harry)
       
       
    4. Me = grandpaw(Me, myself)
       
       
  11. (6 points) In Prolog, assume you have a number of facts of the form:
    male(X).     /* X is a male. */
    female(X).   /* X is a female. */
    child(X, Y). /* X is a child of Y. */
    

    Write Prolog rules (one each) for:

    mother(X, Y).       /* X is the mother of Y. */
    
    
    
    grandmother(X, Y).  /* X is the mother of a parent of Y. */
    
    
    
    sibling(X, Y).      /* X and Y have the same mother and father. */
    
    

     

  12. (8 points) In Prolog,  
    1. If a name begins with a capital letter, it denotes a __________.  
    2. A "predicate" consists of one or more __________.  
    3. The "don't care" variable is written as __________.  
    4. If you want a string to have the value "don't care", the way you would write this string in Prolog is ____________________.  
       
  13. (10 points) What will be the result of evaluating each of the following Lisp functions?
     
    1. (car '(a b c))
       
    2. (car '((a b) (c d)))
       
    3. (car '(()))
       
    4. (cdr '(a b c))
       
    5. (cdr '((a b) (c d))
       
    6. (cdr '(()))
       
    7. (cons 'x '(a b c))
       
    8. (cons '(a b) '(c d))
       
    9. (cons '() '())
       
    10. (eq 'a 'A)
       
    11. (eq '(a b) '(a b))
       
    12. (cond  ((cdr '(a)) 1)  (t 2) )
       
    13. (null nil)
       
    14. (cons (car '(a b c)) (cdr '(a b c))
       
    15. (list (car '(a b c)) (cdr '(a b c)))
       
  14. (2 points) In Lisp, COND is not a function but a "special form." What does this mean?

     
     
     
  15. (4 points) (Fill in the blanks) In Lisp, one technique for writing a complicated function is to:
    Start the function body with a __________, test for __________, do something with the __________, and recur with the __________.
     
  16. (16 points) What will be the result of executing each of the following Haskell 98 commands?

     
    1. length "hello"
       
    2. take 5 [2, 3..]

       
    3. map even [1..10]

       
    4. filter even [1..10]

       
    5. init [1..5]

       
    6. [x | x <- [1..5]]

       
    7. [x | x <- [1..5], even x]

       
    8. [(x,y) | x <- [1, 2], y <- [1..2]]

       
    9. init "curry"

       
    10. break (== 'c') "abracadabra"

       
    11. break (== 'c') "abracadabra"

       
    12. map f [1..5] where f = (3 -)

       
    13. :type even

       
    14. 2 : "abc"

       
    15. take 5 (iterate (2 *) 1)

       
    16. f [1..3] where f x@(y:z) = (x, y, z)

       

  17. (2 points) What is the name of the technique that Haskell uses that allows it to have infinite lists?
     
     
  18. (2 points) Haskell is supposed to be "strongly typed," yet you seldom have to declare the types of your variables. Why is this?

     
     

Please sign and date: I promise not to discuss the contents of this exam with anyone until after the end of the semester.
Signed ___________________ Date __________