;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Exercice 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 1- (append '(1 2) '(3 4)) -> (1 2 3 4) ;; 2- (cons '(1 2) '(3 4)) -> ((1 2) 3 4) ;; 3- (cons '(1 2) 3) -> ((1 2) . 3) ;; 4- (list 'a (+ 2 3)) -> (A 5) ;; 5- '(a (+ 2 3)) -> (A (+ 2 3)) ;; 6- (mapcar #'max '(2 4 7) '(5 3 8)) -> (5 4 8) ;; 7- (find-if (lambda (x) (zerop (car x))) ;; '((1 . a) (0 . b) (2 . c) (0 . d) (3 . e))) -> (0 . B) ;; 8- (find-if #'evenp '(1 2 3 4 5) :from-end t) -> 4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Exercice 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun mapfun (funs x) (mapcar (lambda (f) (funcall f x)) funs)) ;; 2.1 Si funs est une liste de fonctions (f1 f2 ... fn) et x appartient ;; au domaine de définition de ces fonctions ;; (mapfun funs x) retourne la liste (f1(x) f2(x) ... fn(0)) ;; 2.2 ;; (mapfun (list #'1+ (lambda (x) (* x x))) 3) -> (4 9) ;; 2.1 (defun which (fns x) (remove nil (mapcar (lambda (fx f) (when fx f)) (mapfun fns x) fns))) ;; ou avec mapcan (defun which (fns x) (mapcan (lambda (y f) (if y (list f) '())) (mapfun fns x) fns)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Exercice 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 3.1 (defun serie-left-shift (f) (lambda (n) (funcall f (1+ n)))) ;; 3.2 (defun serie-plus (f g) (lambda (n) (+ (funcall f n) (funcall g n)))) ;; 3.3 (defun serie-eval (s x n) (if (zerop n) 0 (+ (funcall s 0) (* x (serie-eval (serie-left-shift s) x (1- n)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Exercice 4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 4.1 (defun random-partition (n) (if (zerop n) '() (let ((i (1+ (random n)))) (cons i (random-partition (- n i)))))) ;; 4.2 (defun suivant (partition) (remove 0 (cons (length partition) (mapcar #'1- partition))))