Advertisement
twinfacer

lisp funcs

Dec 17th, 2013
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.78 KB | None | 0 0
  1. (defun odd_poz(x)
  2.     (cond
  3.         ((null x) nil)
  4.         ((eq (mod (car x) 2) 1)
  5.             (cond
  6.                 ( (> (car x) 0) (car x) )
  7.                 (t(odd_poz(cdr x)))))
  8.         (t (odd_poz(cdr x)))))
  9.  
  10.  
  11. (defun oddpositive(x)
  12.   (cond
  13.     ((null x) nil)
  14.     ((> (car x) 0) (cons (car x) (oddpositive(cdr(cdr x))) ))
  15.     (t(oddpositive(cdr(cdr x))))))
  16.  
  17. (defun join(x y)
  18.   (cond
  19.     ((null x) y)
  20.     (t(cons (car x) (join (cdr x) y) ))))
  21.  
  22. (defun evens(x)
  23.   (cond
  24.     ((null x) nil)
  25.     ((eq (mod (car x) 2) 0)
  26.       (join (car x) (evens(cdr x))))
  27.     (t(evens(cdr x)))
  28. ))
  29.  
  30. (defun last(x)
  31.   (cond
  32.     ((null (cdr x)) (car x))
  33.     (t( last(cdr x)))))
  34.  
  35. (odd_poz '(-6 8 11 4 -16 55 -11 85 88))
  36. (oddpositive '(-6 8 11 4 -16 55 -11 85 88))
  37. (evens '(-6 8 11 4 -16 55 -11 85 88))
  38. (last '(-6 8 11 4 -16 55 -11 85 88))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement