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