Skip to content

Instantly share code, notes, and snippets.

@oxitnik
Created May 4, 2012 20:00
Show Gist options
  • Save oxitnik/2597354 to your computer and use it in GitHub Desktop.
Save oxitnik/2597354 to your computer and use it in GitHub Desktop.
lab4
;1
(defun factorial (n)
(if (equal n 1) 1 (* n (factorial(- n 1))))
)
(defun map-factorial (lst)
(mapcar 'factorial lst)
)
;2
(defun map-sum (l1 l2)
(mapcar (lambda (a b) (+ (abs a) (abs b))) l1 l2)
)
;3
(defun lstsum (lst)
(cond
((numberp lst) lst)
((null lst) 0)
(t (+ (lstsum (car lst)) (lstsum (cdr lst))))
)
)
;4
(defun neg2nul (lst)
(cond
((numberp lst) (if (< lst 0) 0 lst))
((null lst) ())
(t (cons (neg2nul (car lst)) (neg2nul (cdr lst))))
)
)
;5
(defun add1 (lst)
(cond
((numberp lst) (+ lst 1))
((null lst) ())
(t (cons (add1 (car lst)) (add1 (cdr lst))))
)
)
;6
(defun cprod (xs ys)
(mapcan (lambda (x) (mapcar (lambda (y) (list x y)) ys)) xs))
;7
(defun every1 (pred lst)
(reduce (lambda (a b) (and a b)) (mapcar pred lst)))
;8
(defun some1 (pred lst)
(reduce (lambda (a b) (or a b)) (mapcar pred lst)))
;9
(defun a-apply (fl xl)
(mapcar (lambda (f x) (funcall f x)) fl xl )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment