For example: (number '(a b c d)) returns 4 (number '(a (b (c d)))) returns 2
============================================== 2. Write the function REVERSE using: the "do" loop structure. ===============================================
3. The function REMBER was given in class in recursive form and removes a member atom from a list of atoms. Rewrite the function using the DO structure this time.
=============================================
4. Write the function LASTS which accepts as argument a list of sublists and returns a list containing the last elements of each sublist:
Using recursion. (name your function LastsRec) ============================================== 5. Write a function ORDERED which returns true if the numbers in a list are in ascending order.
For example: (ordered '(3 5 7 10)) returns: T (ordered '(8 6 5 3)) returns: nil ======================================== 6. Write the function DIFFERENCE which computes the set theoretic difference of two lists. For example,
(difference '(a b c d) '(c a g))
returns the list (b d) ======================================== EXERCISE 7 is due on Jan. 18 th, by email to chris@cs1.bradley.edu 7. Given the following adjacency list representation of a weighted graph in LISP: (setq graph '( (a (b 3) (c 1)) (b (a 3) (d 1)) (c (a 1) (d 2) (e 2)) (d (b 1) (c 2) (e 1) (g 2)) (e (c 2) (d 1) (f 3)) (f (e 3) (g 1)) (g (d 2) (f 1)) ) ) The numbers next to each node indicate the distances from head of linked list to that node. Here is a non-recursive Program to perform DFS of a graph. Understand it, fix it (there are three errors in program) and run it on the graph representation given above. (defun dfs(graph s d) (do((l ())(g s)(m (list s))) ((eq g d)(setq l (reverse (cons d l)))) (cond (( (exist g l))(setq l (cons g l)) (setq m (append (sub graph g)(cdr m))) (setq g (car m))) (T (setq m (cdr m))(setq g (car m))) ))) (defun super(l n) (do ((m l (cdr m))) ((eq n (car m))(car m)) )) (defun sub(l m) (setq r ()) (do((n (cdr (super l m)) (cdr n))) ((null n) r) (setq r (append r (list (car (car n))))) )) (defun exist(x l) (cond ((null l) nil) ((not (eq x (car l))) T) (T (exist x (cdr l))) )) =================================================== ___________________________________________________