;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Exercice 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun test-predicates (objects pvector) (let* ((len (length pvector)) (res (make-array len :initial-element '()))) (dolist (o objects res) (dotimes (i len) (when (funcall (aref pvector i) o) (push o (aref res i))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Exercice 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 1. (defclass zone () ()) (defclass point () ((x :initarg :x :reader point-x) (y :initarg :y :reader point-y))) (defclass elementary-zone (zone) ()) (defclass polygonal-zone (elementary-zone) ((corners :initarg :corners :reader corners))) (defclass function-zone (elementary-zone) ((fun :initarg :function :reader characteristic-fun))) (defclass circular-zone (elementary-zone) ((center :initarg :center :reader center) (radius :initarg :radius :reader radius))) ;; 2. Hiérarchie des classes ;; 3. (defgeneric point-in-zone-p (point zone)) ;; 4. (defmethod point-in-zone-p (point (zone function-zone)) (funcall (characteristic-fun zone) point)) ;; 5 (defmethod point-in-zone-p (point (zone circular-zone)) (let ((dist-x (- (point-x point) (point-x (center zone)))) (dist-y (- (point-y point) (point-y (center zone))))) (<= (+ (* dist-x dist-x) (* dist-y dist-y)) (* (radius zone) (radius zone))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Exercice 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 1- 5 ;; 2- 10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Exercice 4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CL-USER> (defparameter *l* '(1 2 3 4)) *L* ;; Réponse 1 CL-USER> (macroexpand-1 '(push-ntimes 0 *l* 3)) (PROGN (PUSH 0 *L*) (PUSH 0 *L*) (PUSH 0 *L*)) ;; Réponse 2 T CL-USER> (push-ntimes 0 *l* 3) (0 0 0 1 2 3 4) ;; Réponse 3 CL-USER> *l* (0 0 0 1 2 3 4) ;; Réponse 4 CL-USER> (defparameter *x* 5) *X* ;; Réponse 5 CL-USER> (macroexpand-1 '(push-ntimes (incf *x*) *l* 3)) (PROGN (PUSH (INCF *X*) *L*) ;; Réponse 6 (PUSH (INCF *X*) *L*) (PUSH (INCF *X*) *L*)) T CL-USER> (push-ntime (incf *x*) *l* 3) (8 7 6 0 0 0 1 2 3 4) ;; Réponse 7 (defmacro push-ntimes (e l &optional (n 1)) (let ((ee (gensym))) `(let ((,ee ,e)) ,@(loop repeat n collect `(push ,ee ,l)))))