Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun fact(n) ; Problema 1
- (cond ((zerop n) 1)
- ((equal n 1) 1)
- (t (* n (fact (- n 1))))
- )
- )
- (defun fibonacci(n) ; Problema 2
- (cond ((zerop n) 0)
- ((equal n 1) 1)
- ((+ (fibonacci(- n 1)) (fibonacci(- n 2))))
- )
- )
- (defun my_member(x lst) ; Problema 3
- (cond ((null lst) nil)
- ((equal (car lst) x) t)
- ((my_member x (cdr lst)))
- )
- )
- (defun trim-head (lst n) ; Problema 4
- (cond ((> n (length lst)) '(nil))
- ((null lst) '(nil))
- ((zerop n) lst)
- (t (trim-head (cdr lst) (- n 1)))
- )
- )
- (defun trim-tail (lst n) ; Problema 5
- (reverse (trim-head (reverse lst) n))
- )
- (defun count-atoms (lst) ; Problema 6
- (cond ((null lst) 0)
- (t (+ (cond ((atom (car lst)) 1)
- ((count-atoms (car lst))))
- (count-atoms (cdr lst))))
- )
- )
- (setq lst '(1 4 5))
- (print (my_member 3 lst))
- (print (fibonacci 10))
- (print (trim-tail '(1 2 3 4 5) 2))
- (print (count-atoms '(a b ((a) c) e)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement