LISP - Problem 2 Solution for Problem 1:

(define long  (s) 
     (cond 
         ((null s) 0)
         (t (+ 1 (long (cdr s))))
     )
)

LISP - Problem 2

Larger versions of LISP and SCHEME permit the use of a form of "if-statement" which has the syntax (if condition then-value else-value). Thus evaluating (if t 5 19) would result in 5 while (if (eq 4 0) 'a 'g) would produce g. Implement the if function.

You may check out the validity of your implementation at any time using the EVALUATE button and editing the function definition as necessary. We recommend that you copy the function definition each time you edit it, so that you can reconstruct and edit it as you go along. Once you have completed your implementation of this function, click on the DONE button to submit your solution to the grader and score recorder. A new problem will then be displayed.


Last updated 2001/06/22
© J.A.N. Lee, 2001.