Assignment: #FinalAssessment Due: 12/14/02018 Points: 15
  1. Match programming language with its creator.

       Stroustrup      C
       McCarthy        Prolog
       Colmerauer      C++
       Ritchie         Lisp
    


  2. List the languages C++, Lisp, Prolog by age in oldest-to-newest order.


  3.    int x[] =  { 110, 205, 120, 240, };    // C++
       (setf alist (list 110 205 120 240))    ; Lisp
    
    Write a Lisp expression that evaluates to the C++ expression x[3].


  4. Briefly explain the "meanings" associated with the programming language names C++, Lisp, Prolog.


  5. "In the original LISP there were two fundamental data types: atoms and lists." Lists are also supported in Prolog. In C and C++, a list can be implemented using what language supported data structure?


  6. Using the Lisp list (110 205 240), draw a box diagram that shows the list as a singly-linked-list.


  7. 
    Write a Lisp expression that that uses the list 
    (2 4 0) to evaluate to 
    Head in the Prolog clause: 
    [2, 4, 0] = [Head | Tail].
    


  8. In C++ the semi-colon is a statement terminator. In Lisp the semi-colon is used to insert what into the code? In Prolog, when used in a rule, the semi-colon is used as what type of logical operator?


  9.    X is mod(24, 7).      % Prolog: variable X is unified with 3
       (setf X (mod 24 7))   ; Lisp: variable X is set to 3
    

    Rewrite the Prolog and Lisp code in C++.


  10. Using the following function...

       (defun foo (x y) (if (zerop y) x (foo y (mod x y))))
    

    record what (foo 56 48) evaluates to and briefly explain why.


  11. Write a Lisp expression that evaluates the following infix arithmetic expression.

       (3.14 - 1.618) / 1.618 * 100
    

  12. Record what the following C++ code snippet prints.

       char x[] = { 'd', 'w', 'o', ' ', 'g', 'b', 'l', 'e', 'r', 'y', ',' };
       int y[] = { 4, 2, 2, 0, 5, 9, 7, 10, 3, 1, 2, 8, 6, 0, -1 };
       for (int z = 0; y[z] != -1; z++) 
          cout << x[y[z]];
       cout << endl;
    

  13. The next four questions use the following Prolog knowledge base.

       healthy(gerald).
       over65(truman).
       over65(betty).
       retired(betty).
       retired(truman).
       wealthy(truman).
       wise(truman).
       happy(X) :- wealthy(X), healthy(X), wise(X).
       senior(X) :- retired(X); over65(X).
    
  14. Briefly explain why the query  wise(truman).  evaluates to true.
  15. Briefly explain why the query  over65(gerald).  evaluates to false.
  16. Briefly explain why the query  happy(truman).  evaluates to false.
  17. List all the values Prolog would assign to X given the query:  retired(X).

  18. The following is a C++ function prototype.

       void foo(int, int*, int&);
    

    Briefly explain what the function prototype is declaring.


  19. The next five questions use the following Prolog knowledge base.

       a(1).
       b(1).
       b(2).
       c(1).
       c(2).
       d(2).
       e(2).
       e(4).
       f(3).
       p(X) :- a(X).                      % rule 1
       p(X) :- b(X), c(X), d(X), e(X).    % rule 2
       p(X) :- f(X).                      % rule 3
       p(X) :- e(X); f(X).                % rule 4
    
  20. Briefly explain why the query  p(1).  evaluates to true.
  21. Briefly explain why the query  p(2).  evaluates to true.
  22. Briefly explain why the query  p(3).  evaluates to true.
  23. Briefly explain why the query  p(4).  evaluates to true.
  24. Briefly explain why the query  p(5).  evaluates to false.

  25. Evaluate:  (* (+ (expt 2 3) (expt 3 0) 5 -4 (* 2 5)) (/ 24 2))

  26. Evaluate:
    (setf x (list "240" "scc" "foo" "csc" "done"))
    (format t "~a~a at ~a is ~a" (fourth x) (car x) (cadr x) (car (last x)))