fork download
  1. ;; Гласные буквы русского языка (без изменений)
  2. (defun vowel-p (char)
  3. (member char '(#\а #\е #\ё #\и #\о #\у #\ы #\э #\ю #\я
  4. #\А #\Е #\Ё #\И #\О #\У #\Ы #\Э #\Ю #\Я)
  5. :test #'char=))
  6.  
  7. ;; Согласные буквы русского языка (без изменений)
  8. (defun consonant-p (char)
  9. (not (vowel-p char)))
  10.  
  11. ;; Функция для проверки наличия "й" после гласной (без изменений)
  12. (defun yot-after-vowel-p (chars index)
  13. (and (< (1+ index) (length chars))
  14. (char= (elt chars (1+ index)) #\й)
  15. (vowel-p (elt chars index))))
  16.  
  17. ;; Разбиение слова на слоги (рекурсивная версия)
  18. (defun split-word (word)
  19. (labels ((split-word-recursive (chars syllables current index)
  20. (cond
  21. ((>= index (length chars)) ; Базовый случай: конец слова
  22. (if current
  23. (if syllables
  24. (list
  25. (concatenate 'string (car syllables) (coerce (reverse current) 'string))
  26. (cdr syllables))
  27. (list (coerce (reverse current) 'string)))
  28. syllables)) ; return result
  29.  
  30. (t (let* ((ch (elt chars index))
  31. (new-current (cons ch current))) ; Добавляем текущий символ к текущему слогу
  32. (cond
  33. ((vowel-p ch)
  34. (if (yot-after-vowel-p chars index)
  35. (let* ((next-index (+ index 2))
  36. (yot-char (elt chars (1+ index)))
  37. (new-current-with-yot (cons yot-char new-current))
  38. (new-syllable (coerce (reverse new-current-with-yot) 'string))
  39. (new-syllables (cons new-syllable syllables)))
  40. (split-word-recursive chars new-syllables nil next-index)) ; start new
  41. (let* ((new-syllable (coerce (reverse new-current) 'string))
  42. (new-syllables (cons new-syllable syllables))
  43. (next-index (1+ index)))
  44. (split-word-recursive chars new-syllables nil next-index)))) ; start new
  45. (t (split-word-recursive chars syllables new-current (+ index 1))))))))) ; next char
  46. (reverse (split-word-recursive (coerce word 'list) nil nil 0)))) ; Start
  47.  
  48.  
  49. ;; Разбиение строки на слова (рекурсивная версия)
  50. (defun split-string (str)
  51. (labels ((split-string-recursive (str words current index)
  52. (cond
  53. ((>= index (length str))
  54. (if current
  55. (reverse (cons (coerce (reverse current) 'string) words))
  56. (reverse words))) ; return result
  57. (t (let ((ch (char str index)))
  58. (if (char= ch #\Space)
  59. (if current
  60. (split-string-recursive str (cons (coerce (reverse current) 'string) words) nil (+ index 1))
  61. (split-string-recursive str words nil (+ index 1))) ; space
  62. (split-string-recursive str words (cons ch current) (+ index 1)))))))) ;next char
  63. (split-string-recursive str nil nil 0))) ; Start
  64.  
  65.  
  66. ;; Главная функция с использованием MAPCAR (без изменений)
  67. (defun split-phrase (phrase)
  68. (mapcar #'split-word (split-string phrase))) ; Using MAPCAR
  69.  
  70. ;; Тесты (без изменений)
  71. (print (split-phrase "написать программу"))
  72. (print (split-phrase "дана фраза на русском языке"))
  73. (print (split-phrase "война, мир, эвакуатор"))
  74. (print (split-phrase "скамейка"))
  75. (print (split-phrase "ванна"))
  76. (print (split-phrase "коллекция"))
  77. (print (split-phrase "чай"))
  78.  
  79.  
Success #stdin #stdout #stderr 0.01s 9588KB
stdin
Standard input is empty
stdout
((("пи" "на") "сать") ("про" "гра" "мму")) 
(("да" "на") ("фра" "за") ("на") (("ру") "сском") ("я" "зы" "ке")) 
((("вой") "на,") (NIL "мир,") (("а" "ку" "ва" "э") "тор")) 
(("ска" "мей" "ка")) 
(("ва" "нна")) 
(("ко" "лле" "кци" "я")) 
(("чай")) 
stderr
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