(defun position-all (ch) #'(lambda (str) (labels ((inner (n l rv) (cond ((<= l n) (reverse rv)) (t (let ((pos (position ch str :start n))) (if pos (inner (1+ pos) l (cons pos rv)) (reverse rv))))))) (inner 0 (length str) '())))) (defun titles (str) (let ((positions (cons -1 (funcall (position-all #\Space) str)))) (labels ((inner (lst rv) (if (endp lst) (reverse rv) (let ((n (first lst))) (if (and (<= 3 (length lst)) (= (+ n 1) (second lst)) (= (+ n 2) (third lst))) (inner (nthcdr 2 lst) (cons #\Space rv)) (inner (cdr lst) (cons (elt str (1+ n)) rv))))))) (inner positions '())))) (format t "~{~a~}~%" (titles (read-line)))