| CSC 1800 Final Exam Villanova University, Fall 2000 |
Name __________________________________________ |
Please keep all answers brief and to the point. Illegible answers will be counted
as wrong. None of the questions ask for examples.
General Questions
<thing> ::= <x> y
<x> ::= a | b | c | <x> * <thing>
<thing>?
(Write "yes" or "no" for each.)
- x y
- a x b y
- a * b y
- a y * b y
- y * x y
- b * c * a y y
LISP Questions
(CAR '(A
B C) )
(CAR '((A)
(B) (C)) )
(CAR '(()
()) )
(CDR '(A
(B)) )
(CDR '(() ()) )
(CONS '() '(A B) )
(APPEND '(A ()) '(B ()) )
(LIST '(A B) '(C D) )
(CAAR '((A B) (C D)) )
(CADR '((A B) (C D)) )
(CDAR '((A B) (C D)) )
(CDDR '((A B) (C D)) )
(defun puzzle (a lat)
(cond ((null lat) ())
((eq a (car lat)) (puzzle a (cdr lat)))
(t (cons (car lat) (puzzle a (cdr lat)))) ) )
what is the result of the following function calls?
(puzzle 'a '(a b r a c a d a b r a) )
(puzzle 'a '(a (a b) b (b a) a) )
(defun confuse (L1 L2)
(cond
(null L1) L2)
(T (confuse (cdr L1) (cons (car L1) L2))) ) )
what is the result of the following function calls?
(confuse '((A) B) '(C (D)))
(confuse '(A (B)) '((C) D))
cdr is faster than cons. (EQ () ()) is a legal function call. T or NIL. NIL is a list. COND evaluates to
NIL.ML Questions
odd that returns true
if its integer parameter is odd, and false otherwise.string list
int -> real
((int * int) * real)
#"a"
not
round
[#"a"]
fun confound x [] = [x]
| confound x (y::ys) = y::(confound x ys);
what is the result of the following function calls?
confound 1 [2];
confound 1 [2,3,4];
fun bamboozle [] = []
| bamboozle (x::xs) = (bamboozle xs) @ [x];
what is the result of the following function calls?
bamboozle [1,2];
bamboozle [1,2,3,4];
fun mapkin L = map (fn x => x mod 2 = 0) L;
what is the result of the following function calls?
mapkin [1,2,3];
mapkin [~2, ~1, 0, 1, 2];
load function.Feel free to use the rest of this space as scratch paper.