(lambda (l k)
(if (null? l)
()
(if (equal? k (car (car l)))
(car (cdr (car l)))
(lookup (cdr l) k))) )
2) Write me a Prolog program that can answer questions of the form
'which programming languages use semi-colons' and 'which programming languages
are graphical?' or even 'which langauges are both s The data is shown
below.
C | Semi-colons | ||
C++ | Semi-colons | Object-oriented | |
Java | Semi-colons | Object-oriented | Graphical |
Lisp | Parenthesis | List-Oriented | |
Prolog | Periods | Horn-clauses |
semi(c).
semi(cplus).
semi(java).
parens(lisp).
period(prolog).
graphical(java).
oo(cplus).
oo(java).
list(lisp).
horn(prolog).
3) Recall that the factorial of n is just n * (n-1) *
(n-2) * (n-3) ... * 2 * 1. Write me a lisp function 'fac'
that takes as an argument a positive integer. Fac should return the
factorial of the integer.
(fac 3) -> 6 (fac 5) -> 120
(lambda (n)
(if (= n 1)
1
(* n (fac (- n 1)))) )