Поиск гласных букв - Lisp

Узнай цену своей работы

Формулировка задачи:

Для данного текстового файла проверить следующую гипотезу: «Самые часто встречающиеся гласные – это А, Е, О» можеть кто-то реализовать?

Решение задачи: «Поиск гласных букв»

textual
Листинг программы
(defconstant *s* "Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 (R2004) (formerly X3.226-1994 (R1999)). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived from the ANSI Common Lisp standard. The Common Lisp language was developed as a standardized and improved successor of Maclisp. By the early 1980s several groups were already at work on diverse successors to MacLisp: Lisp Machine Lisp (aka ZetaLisp), Spice Lisp, NIL and S-1 Lisp. Common Lisp sought to unify, standardise, and extend the features of these MacLisp dialects. Common Lisp is not an implementation, but rather a language specification.[3] Several implementations of the Common Lisp standard are available, including free and open source software and proprietary products. Common Lisp is a general-purpose, multi-paradigm programming language. It supports a combination of procedural, functional, and object-oriented programming paradigms. As a dynamic programming language, it facilitates evolutionary and incremental software development, with iterative compilation into efficient run-time programs that can be as performant as those written in C. This incremental development is often done interactively without interrupting the running application. It also supports optional type annotation and casting, which can be added as necessary at the later profiling and optimization stages, to permit the compiler to generate more efficient code. For instance, fixnum can hold an unboxed integer in a range supported by the hardware and implementation, permitting more efficient arithmetic than on big integers or arbitrary precision types. Similarly, the compiler can be told on a per-module or per-function basis which type safety level is wanted, using optimize declarations. Common Lisp includes CLOS, an object system that supports multimethods and method combinations. It is often implemented with a Metaobject Protocol. Common Lisp is extensible through standard features such as Lisp macros (code transformations) and reader macros (input parsers for characters). Common Lisp provides some backwards compatibility to Maclisp and to John McCarthy's original Lisp. This allows older Lisp software to be ported to Common Lisp")
 
(defun eai-most-frequentp (s)
  (not (set-difference
        '(#\e #\a #\i)
        (subseq (mapcar #'car
                        (sort (aeiouy-frequency s)
                              #'> :key #'cadr))
                0 3)
        :test #'char-equal)))
 
(defun aeiouy-frequency (s)
  (loop for a in '(#\a #\e #\i #\o #\u #\y) 
        collect (list a (count a s))))
 
> (aeiouy-frequency *s*)
((#\a 159) (#\e 179) (#\i 151) (#\o 141) (#\u 41) (#\y 22))
> (eai-most-frequentp *s*)
T

Объяснение кода листинга программы

  1. Объявлена константа s с значением Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 (R2004) (formerly X3.226-1994 (R1999)). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived from the ANSI Common Lisp standard. The Common Lisp language was developed as a standardized and improved successor of Maclisp. By the early 1980s several groups were already at work on diverse successors to MacLisp: Lisp Machine Lisp (aka ZetaLisp), Spice Lisp, NIL and S-1 Lisp. Common Lisp sought to unify, standardise, and extend the features of these MacLisp dialects. Common Lisp is not an implementation, but rather a language specification.[3] Several implementations of the Common Lisp standard are available, including free and open source software and proprietary products. Common Lisp is a general-purpose, multi-paradigm programming language. It supports a combination of procedural, functional, and object-oriented programming paradigms. As a dynamic programming language, it facilitates evolutionary and incremental software development, with iterative compilation into efficient run-time programs that can be as performant as those written in C. This incremental development is often done interactively without interrupting the running application. It also supports optional type annotation and casting, which can be added as necessary at the later profiling and optimization stages, to permit the compiler to generate more efficient code. For instance, fixnum can hold an unboxed integer in a range supported by the hardware and implementation, permitting more efficient arithmetic than on big integers or arbitrary precision types. Similarly, the compiler can be told on a per-module or per-function basis which type safety level is wanted, using optimize declarations. Common Lisp includes CLOS, an object system that supports multimethods and method combinations. It is often implemented with a Metaobject Protocol. Common Lisp is extensible through standard features such as Lisp macros (code transformations) and reader macros (input parsers for characters). Common Lisp provides some backwards compatibility to Maclisp and to John McCarthy's original Lisp. This allows older Lisp software to be ported to Common Lisp)
  2. Определена функция eai-most-frequentp, которая проверяет, является ли гласной буква, наиболее часто встречающейся в строке, гласной e.
  3. Определена функция aeiouy-frequency, которая считает частоту встречаемости гласных букв в строке.
  4. Выполнена функция aeiouy-frequency для строки s, результат: ((#\a 159) (#\e 179) (#\i 151) (#\o 141) (#\u 41) (#\y 22))
  5. Выполнена функция eai-most-frequentp для строки s, результат: T (истина)

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 4 из 5
Похожие ответы