;; Гласные буквы русского языка (без изменений) (defun vowel-p (char) (member char '(#\а #\е #\ё #\и #\о #\у #\ы #\э #\ю #\я #\А #\Е #\Ё #\И #\О #\У #\Ы #\Э #\Ю #\Я) :test #'char=)) ;; Согласные буквы русского языка (без изменений) (defun consonant-p (char) (not (vowel-p char))) ;; Функция для проверки наличия "й" после гласной (без изменений) (defun yot-after-vowel-p (chars index) (and (< (1+ index) (length chars)) (char= (elt chars (1+ index)) #\й) (vowel-p (elt chars index)))) ;; Разбиение слова на слоги (рекурсивная версия) (defun split-word (word) (labels ((split-word-recursive (chars syllables current index) (cond ((>= index (length chars)) ; Базовый случай: конец слова (if current (if syllables (list (concatenate 'string (car syllables) (coerce (reverse current) 'string)) (cdr syllables)) (list (coerce (reverse current) 'string))) syllables)) ; return result (t (let* ((ch (elt chars index)) (new-current (cons ch current))) ; Добавляем текущий символ к текущему слогу (cond ((vowel-p ch) (if (yot-after-vowel-p chars index) (let* ((next-index (+ index 2)) (yot-char (elt chars (1+ index))) (new-current-with-yot (cons yot-char new-current)) (new-syllable (coerce (reverse new-current-with-yot) 'string)) (new-syllables (cons new-syllable syllables))) (split-word-recursive chars new-syllables nil next-index)) ; start new (let* ((new-syllable (coerce (reverse new-current) 'string)) (new-syllables (cons new-syllable syllables)) (next-index (1+ index))) (split-word-recursive chars new-syllables nil next-index)))) ; start new (t (split-word-recursive chars syllables new-current (+ index 1))))))))) ; next char (reverse (split-word-recursive (coerce word 'list) nil nil 0)))) ; Start ;; Разбиение строки на слова (рекурсивная версия) (defun split-string (str) (labels ((split-string-recursive (str words current index) (cond ((>= index (length str)) (if current (reverse (cons (coerce (reverse current) 'string) words)) (reverse words))) ; return result (t (let ((ch (char str index))) (if (char= ch #\Space) (if current (split-string-recursive str (cons (coerce (reverse current) 'string) words) nil (+ index 1)) (split-string-recursive str words nil (+ index 1))) ; space (split-string-recursive str words (cons ch current) (+ index 1)))))))) ;next char (split-string-recursive str nil nil 0))) ; Start ;; Главная функция с использованием MAPCAR (без изменений) (defun split-phrase (phrase) (mapcar #'split-word (split-string phrase))) ; Using MAPCAR ;; Тесты (без изменений) (print (split-phrase "написать программу")) (print (split-phrase "дана фраза на русском языке")) (print (split-phrase "война, мир, эвакуатор")) (print (split-phrase "скамейка")) (print (split-phrase "ванна")) (print (split-phrase "коллекция")) (print (split-phrase "чай"))
Standard input is empty
((("пи" "на") "сать") ("про" "гра" "мму"))
(("да" "на") ("фра" "за") ("на") (("ру") "сском") ("я" "зы" "ке"))
((("вой") "на,") (NIL "мир,") (("а" "ку" "ва" "э") "тор"))
(("ска" "мей" "ка"))
(("ва" "нна"))
(("ко" "лле" "кци" "я"))
(("чай"))
Warning: reserving address range 0x80000c0000...0x1fffffffffff that contains memory mappings. clisp might crash later! Memory dump: 0x8000000000 - 0x80000bffff 0x14e8f1600000 - 0x14e8f18e4fff 0x14e8f1a15000 - 0x14e8f1a39fff 0x14e8f1a3a000 - 0x14e8f1bacfff 0x14e8f1bad000 - 0x14e8f1bf5fff 0x14e8f1bf6000 - 0x14e8f1bf8fff 0x14e8f1bf9000 - 0x14e8f1bfbfff 0x14e8f1bfc000 - 0x14e8f1bfffff 0x14e8f1c00000 - 0x14e8f1c02fff 0x14e8f1c03000 - 0x14e8f1e01fff 0x14e8f1e02000 - 0x14e8f1e02fff 0x14e8f1e03000 - 0x14e8f1e03fff 0x14e8f1e80000 - 0x14e8f1e8ffff 0x14e8f1e90000 - 0x14e8f1ec3fff 0x14e8f1ec4000 - 0x14e8f1ffafff 0x14e8f1ffb000 - 0x14e8f1ffbfff 0x14e8f1ffc000 - 0x14e8f1ffefff 0x14e8f1fff000 - 0x14e8f1ffffff 0x14e8f2000000 - 0x14e8f2003fff 0x14e8f2004000 - 0x14e8f2203fff 0x14e8f2204000 - 0x14e8f2204fff 0x14e8f2205000 - 0x14e8f2205fff 0x14e8f22f6000 - 0x14e8f22f9fff 0x14e8f22fa000 - 0x14e8f22fafff 0x14e8f22fb000 - 0x14e8f22fcfff 0x14e8f22fd000 - 0x14e8f22fdfff 0x14e8f22fe000 - 0x14e8f22fefff 0x14e8f22ff000 - 0x14e8f22fffff 0x14e8f2300000 - 0x14e8f230dfff 0x14e8f230e000 - 0x14e8f231bfff 0x14e8f231c000 - 0x14e8f2328fff 0x14e8f2329000 - 0x14e8f232cfff 0x14e8f232d000 - 0x14e8f232dfff 0x14e8f232e000 - 0x14e8f232efff 0x14e8f232f000 - 0x14e8f2334fff 0x14e8f2335000 - 0x14e8f2336fff 0x14e8f2337000 - 0x14e8f2337fff 0x14e8f2338000 - 0x14e8f2338fff 0x14e8f2339000 - 0x14e8f2339fff 0x14e8f233a000 - 0x14e8f2367fff 0x14e8f2368000 - 0x14e8f2376fff 0x14e8f2377000 - 0x14e8f241cfff 0x14e8f241d000 - 0x14e8f24b3fff 0x14e8f24b4000 - 0x14e8f24b4fff 0x14e8f24b5000 - 0x14e8f24b5fff 0x14e8f24b6000 - 0x14e8f24c9fff 0x14e8f24ca000 - 0x14e8f24f1fff 0x14e8f24f2000 - 0x14e8f24fbfff 0x14e8f24fc000 - 0x14e8f24fdfff 0x14e8f24fe000 - 0x14e8f2503fff 0x14e8f2504000 - 0x14e8f2506fff 0x14e8f2509000 - 0x14e8f2509fff 0x14e8f250a000 - 0x14e8f250afff 0x14e8f250b000 - 0x14e8f250bfff 0x14e8f250c000 - 0x14e8f250cfff 0x14e8f250d000 - 0x14e8f250dfff 0x14e8f250e000 - 0x14e8f2514fff 0x14e8f2515000 - 0x14e8f2517fff 0x14e8f2518000 - 0x14e8f2518fff 0x14e8f2519000 - 0x14e8f2539fff 0x14e8f253a000 - 0x14e8f2541fff 0x14e8f2542000 - 0x14e8f2542fff 0x14e8f2543000 - 0x14e8f2543fff 0x14e8f2544000 - 0x14e8f2544fff 0x559ae9637000 - 0x559ae9727fff 0x559ae9728000 - 0x559ae9831fff 0x559ae9832000 - 0x559ae9891fff 0x559ae9893000 - 0x559ae98c1fff 0x559ae98c2000 - 0x559ae98f2fff 0x559ae98f3000 - 0x559ae98f6fff 0x559ae9e5a000 - 0x559ae9e7afff 0x7fff9b7c2000 - 0x7fff9b7e2fff 0x7fff9b7f3000 - 0x7fff9b7f6fff 0x7fff9b7f7000 - 0x7fff9b7f8fff