;; Гласные буквы русского языка (defun vowel-p (char) (member char '(#\а #\е #\ё #\и #\о #\у #\ы #\э #\ю #\я #\А #\Е #\Ё #\И #\О #\У #\Ы #\Э #\Ю #\Я) :test #'char=)) ;; Согласные буквы русского языка (defun consonant-p (char) (not (vowel-p char))) ;; Йотированные гласные (defun yotated-vowel-p (char) (member char '(#\е #\ё #\ю #\я #\Е #\Ё #\Ю #\Я) :test #'char=)) ;; Функция для разбиения слова на слоги (defun split-word (word) (labels ((split-word-recursive (chars syllables current i) (cond ((>= i (length chars)) (if current (reverse (cons (coerce (reverse current) 'string) syllables)) (reverse syllables))) (t (let ((ch (elt chars i))) (cond ((vowel-p ch) ;Обработка гласной (cond ((and (= i 0) (yotated-vowel-p ch)) ; Йотированная в начале слова (split-word-recursive chars (cons (string ch) syllables) nil (1+ i))) ((and (> i 0) (vowel-p (elt chars (1- i))) (yotated-vowel-p ch)) ; Йотированная после гласной (split-word-recursive chars (cons (string ch) syllables) nil (1+ i))) ((char= ch #\й) ;Обработка "й" (split-word-recursive chars (cons (coerce (reverse (cons ch current)) 'string) syllables) nil (1+ i))) (t ;Обычная гласная (split-word-recursive chars (cons (coerce (reverse (cons ch current)) 'string) syllables) nil (1+ i)))) ) (t ;Обработка согласной (split-word-recursive chars syllables (cons ch current) (1+ i))))))))) (split-word-recursive (coerce word 'list) nil nil 0))) ;; Разбиение строки на слова (рекурсивная версия без SETF) (defun split-string (str) (labels ((split-string-recursive (str current-word words) (cond ((null str) (if current-word (reverse (cons (coerce (reverse current-word) 'string) words)) (reverse words))) ((char= (car str) #\Space) (if current-word (split-string-recursive (cdr str) nil (cons (coerce (reverse current-word) 'string) words)) (split-string-recursive (cdr str) nil words))) (t (split-string-recursive (cdr str) (cons (car str) current-word) words))))) (split-string-recursive (coerce str 'list) nil nil))) ;; Главная функция с использованием MAPCAR (defun split-phrase (phrase) (mapcar #'split-word (split-string phrase))) ;; Тест (print (split-phrase "написать программу")) (print (split-phrase "дана фраза на русском языке")) (print (split-phrase "война, мир, эвакуатор")) (print (split-phrase "скамейка")) (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
(("на" "пи" "са" "ть") ("про" "гра" "мму"))
(("да" "на") ("фра" "за") ("на") ("ру" "сско" "м") ("я" "зы" "ке"))
(("во" "йна" ",") ("ми" "р,") ("э" "ва" "ку" "а" "то" "р"))
(("ска" "ме" "йка"))
(("ва" "нна"))
(("ко" "лле" "кци" "я"))
(("ча" "й"))
(("ё" "лка"))
(("я" "ма"))
(("ю" "ла"))
(("е" "да"))
Warning: reserving address range 0x80000c0000...0x1fffffffffff that contains memory mappings. clisp might crash later! Memory dump: 0x8000000000 - 0x80000bffff 0x14bced200000 - 0x14bced4e4fff 0x14bced615000 - 0x14bced639fff 0x14bced63a000 - 0x14bced7acfff 0x14bced7ad000 - 0x14bced7f5fff 0x14bced7f6000 - 0x14bced7f8fff 0x14bced7f9000 - 0x14bced7fbfff 0x14bced7fc000 - 0x14bced7fffff 0x14bced800000 - 0x14bced802fff 0x14bced803000 - 0x14bceda01fff 0x14bceda02000 - 0x14bceda02fff 0x14bceda03000 - 0x14bceda03fff 0x14bceda80000 - 0x14bceda8ffff 0x14bceda90000 - 0x14bcedac3fff 0x14bcedac4000 - 0x14bcedbfafff 0x14bcedbfb000 - 0x14bcedbfbfff 0x14bcedbfc000 - 0x14bcedbfefff 0x14bcedbff000 - 0x14bcedbfffff 0x14bcedc00000 - 0x14bcedc03fff 0x14bcedc04000 - 0x14bcede03fff 0x14bcede04000 - 0x14bcede04fff 0x14bcede05000 - 0x14bcede05fff 0x14bcedebc000 - 0x14bcedebffff 0x14bcedec0000 - 0x14bcedec0fff 0x14bcedec1000 - 0x14bcedec2fff 0x14bcedec3000 - 0x14bcedec3fff 0x14bcedec4000 - 0x14bcedec4fff 0x14bcedec5000 - 0x14bcedec5fff 0x14bcedec6000 - 0x14bceded3fff 0x14bceded4000 - 0x14bcedee1fff 0x14bcedee2000 - 0x14bcedeeefff 0x14bcedeef000 - 0x14bcedef2fff 0x14bcedef3000 - 0x14bcedef3fff 0x14bcedef4000 - 0x14bcedef4fff 0x14bcedef5000 - 0x14bcedefafff 0x14bcedefb000 - 0x14bcedefcfff 0x14bcedefd000 - 0x14bcedefdfff 0x14bcedefe000 - 0x14bcedefefff 0x14bcedeff000 - 0x14bcedefffff 0x14bcedf00000 - 0x14bcedf2dfff 0x14bcedf2e000 - 0x14bcedf3cfff 0x14bcedf3d000 - 0x14bcedfe2fff 0x14bcedfe3000 - 0x14bcee079fff 0x14bcee07a000 - 0x14bcee07afff 0x14bcee07b000 - 0x14bcee07bfff 0x14bcee07c000 - 0x14bcee08ffff 0x14bcee090000 - 0x14bcee0b7fff 0x14bcee0b8000 - 0x14bcee0c1fff 0x14bcee0c2000 - 0x14bcee0c3fff 0x14bcee0c4000 - 0x14bcee0c9fff 0x14bcee0ca000 - 0x14bcee0ccfff 0x14bcee0cf000 - 0x14bcee0cffff 0x14bcee0d0000 - 0x14bcee0d0fff 0x14bcee0d1000 - 0x14bcee0d1fff 0x14bcee0d2000 - 0x14bcee0d2fff 0x14bcee0d3000 - 0x14bcee0d3fff 0x14bcee0d4000 - 0x14bcee0dafff 0x14bcee0db000 - 0x14bcee0ddfff 0x14bcee0de000 - 0x14bcee0defff 0x14bcee0df000 - 0x14bcee0fffff 0x14bcee100000 - 0x14bcee107fff 0x14bcee108000 - 0x14bcee108fff 0x14bcee109000 - 0x14bcee109fff 0x14bcee10a000 - 0x14bcee10afff 0x564016868000 - 0x564016958fff 0x564016959000 - 0x564016a62fff 0x564016a63000 - 0x564016ac2fff 0x564016ac4000 - 0x564016af2fff 0x564016af3000 - 0x564016b23fff 0x564016b24000 - 0x564016b27fff 0x564016ef2000 - 0x564016f12fff 0x7ffe8e679000 - 0x7ffe8e699fff 0x7ffe8e755000 - 0x7ffe8e758fff 0x7ffe8e759000 - 0x7ffe8e75afff