;;; 1 (defun display-list (l stream &key (sep " ")) (when l (mapc (lambda (e) (format stream "~A~A " e sep)) (butlast l)) (format stream "~A" (car (last l))))) ;;; 2.1 (defun split (l pred) (let ((lt '()) (lf '())) (dolist (e l (list (nreverse lt) (nreverse lf))) (if (funcall pred e) (push e lt) (push e lf))))) ;;; 2.2 (defun split (l pred) (let ((lt '()) (lf '())) (dolist (e l (values (nreverse lt) (nreverse lf))) (if (funcall pred e) (push e lt) (push e lf))))) ;;; 2.3 (multiple-value-bind (yes no) (split '(1 2 3 4 5) #'evenp) (format t "oui: ~A ~%" yes) (format t "non: ~A ~%" no)) ;;; 3 (defmacro none (&body expressions) `(not (or ,@expressions))) ;;; 4.1 (defclass langage () ((mots :initform nil :initarg :mots :reader mots)) (:documentation "classe des langages")) ;;; 4.2 (defun make-langage (mots) (make-instance 'langage :mots mots)) ;;; 4.3 (defmethod concatenation ((mot1 mot) (mot2 mot)) (make-mot (append (lettres mot1) (lettres mot2)))) ;;; 4.4 (defmethod alphabet ((mot mot)) (remove-duplicates (lettres mot))) ;;; 4.5 (defmethod alphabet ((langage langage)) (remove-duplicates (reduce #'append (mapcar #'alphabet (mots langage))))) ;;; 4.6 (defmethod lunion ((langage1 langage) (langage2 langage)) (make-langage (union (mots langage1) (mots langage2) :test #'equalp)))