L I S P - T E S T


Student name :
Tell us about your programming experience?
have never write a program
Novice
Intermediate programmer
Expert programmer

What level of LISP do you think you are in?
Novice
Intermediate
Advanced


DATA STRUCTURES

  1. Which of the follows are atoms?
    The
    3rd
    empty house
    (moral)
    )vital

  2. Which of the follows are list?
    (the (grand) Canyon)
    (1 2 3 4 5)
    (1 2)(3 4 5)
    ()
    canyon

  3. What is the evaluation of:
    	(car '())
    ()
    Nil
    Error
    None of above

  4. What is the evaluation of:
    	(cdr '())
    ()
    Nil
    Error
    None of above

  5. What is the evaluation of:
        (setq x '(the french Market))
        (car (cdr (car (cdr x))))
    the
    french
    Market
    ()
    None of above

  6. What is the evaluation of:
    	(car (cdr '(the grand canyon)))
    the
    grand
    canyon
    Nil
    None of above

  7. What is the evaluation of:
    	(cdr (car '(the grand canyon)))
    the
    grand
    canyon
    Nil
    None of above

  8. What is the evaluation of:
    	(cdr (cdr '(the grand canyon)))
    the
    (grand canyon)
    (canyon)
    Nil
    None of above

  9. What is the evaluation of:
    	(car (car '(the grand canyon)))
    the
    grand
    canyon
    Nil
    None of above

  10. What is the result of:
    	(car (quote ((you are) right))) 
    you
    you are
    (you are)
    are
    ()
    None of above

  11. Evaluate the result for:
    	(caaaar (cddddr '(a b c d ((((e))))))) 
    a b c d e
    (e) (d) () None of above

  12. What is the result of:
    	(cons '(something) '(is wrong)) 
    (something is wrong)
    ((something) is wrong)
    ((something) (is wrong))
    ((something) (is) wrong)
    something is wrong
    None of above

  13. What would be the statement (using CONS function and single atoms) that produce as a result:
    	(the best coffe) 

  14. What is the result of:
    	(cons 'something (cons (cons 'is '()) '(wrong)) ) 
    (something is wrong)
    ((something) (is) wrong)
    ((something) (is wrong))
    (something (is) wrong)
    something is wrong
    None of above

  15. Write a function THETHIRD that returns the third element of a list l passed as a parameter.
    Example:
    	(THETHIRD '(a b c d) ) = c
            (THETHIRD '(a b)     ) = Nil


    ARITHMETICS

  16. Write the s-expresion equivalent to this formula:
    ((120/4)*(3+2)/15)

  17. Write a function AVGTO ( N , L) that produce the average of the numbers less than N of a list L.

         (AVGTO 10 '(1 2 3 4) = 3
         (AVGTO 0  '(1 2 3 4) = 0
         (AVGTO 3  '(1 2 3 4) = 1.5 

  18. Write a function MULTLIST ( L) that produce as a result the multiplication of all the numbers in the list L.

         (MULTLIST  '(1 2 3 4) = 24
         (MULTLIST  '(3 3 3)   = 27
         (MULTLIST  '(1 2 1 1) = 2 

  19. Write a function FIB(N) that implement the N-esimo fibbonacci number, where the fibbonacci numbers are defined like:
    	FIB (0)	= 0
    	FIB (1) = 1
    	FIB (N) = FIB(N-2) + FIB(n-1),  for N > 1

  20. Write a function COUNTLESS(N L) that counts how many numbers are less than N in the list L.
    Example:
    	(COUNTLESS 3 '(1 2 3 4 5)) = 2
            (COUNTLESS 3 '(4 5 6 7 8)) = 0

  21. Lets define the function FOO as:
    	(DEFUN FOO (L) 
    	  (COND ((NULL L)       0 )
    	        ((NULL (CDR L)) (CAR L))
    	        (t              (* (FOO (CDR L)) 1)  )))
    What is the result of:
    (FOO '(1 2 3 4 5))  =
    1
    2
    3
    4
    5
    None of above


    SETS

  22. Write a function SUBSTRACT (S1 S2) that gives the substraction in sets, where S1 - S2 is all elements that belong to the set S1 but does not belong to the set S2.
    Example:
    	(SUBSTRACT  '(1 2 3 4 5) '(4 5 6 7)) = (1 2 3)
            (SUBSTRACT  '(4 5 6 7 8) '(1 2 3 4)) = (5 6 7 8)

  23. Suppose that we have the function NOIDEA that takes a list L as:
       (DEFUN NOIDEA (L) 
         (COND ((NULL L)       () )
               ((atom (CAR L)) (CONS (CAR L) (NOIDEA (CDR L))))
               (t              (APPEND (NOIDEA (CAR L)) (NOIDEA (CDR L))))))
    • What is the result of:
      (NOIDEA '((THE) (WHITE)(((HOUSE)))) )  =
      THE WHITE HOUSE
      (THE WHITE HOUSE)
      (THE WHITE ((HOUSE)))
      (((THE) (WHITE)(((HOUSE)))))
      None of above

    • What is the result of:
      (NOIDEA '(coffe) )  =
      coffe
      (coffe)
      ((coffe))
      (())
      (coffe ())
      None of above

    • En general, the result of that function is :

      decrease one level in each sublist
      decrease one level in one sublist
      delete all inner parentheses in the list
      None of above

Tutor Index