fork download
  1. ; What does this function f* do?
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 6
  5. ; Exercise 8
  6. ; Common Lisp
  7. ; http://t...content-available-to-author-only...r.com/thelittlelisper
  8. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper-chapter-6-oh-my-gawd-its.html
  9. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
  10. ; ------------------------------
  11. (setf l1 '((fried potatoes)(baked (fried)) tomatoes))
  12. (setf l2 '(((chili) chili (chili))))
  13. (setf l3 '())
  14. (setf lat1 '(chili and hot))
  15. (setf lat2 '(baked fried))
  16. (setf a 'fried)
  17. ; ------------------------------
  18.  
  19. ;need to add member*
  20.  
  21. (defun f* (l acc)
  22. (cond
  23. ((null l) acc)
  24. ((atom (car l))
  25. (cond
  26. ((member (car l) acc) (f* (cdr l) acc))
  27. (t (f* (cdr l)(cons (car l) acc)))))
  28. (t (f* (car l)(f* (cdr l) acc)))))
  29.  
  30. (print (f* '(1 2 3 4 (4 5 3 2 1)) '()))
  31. ;This removes duplicates and returns list in reverse order without sublists
  32.  
Success #stdin #stdout 0.02s 10536KB
stdin
Standard input is empty
stdout
(5 4 3 2 1)