Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 3.80 KB | None | 0 0
  1. ;; LEFTOFF: Conjugating works and you can print the conjugation now properly aligned.
  2.  
  3. ;; We should definte the future indicative, and then have a way to pass the mood-tense
  4. ;; to the conjugate function to get the conjugation list.
  5.  
  6. (in-package #:spanisher)
  7.  
  8. (defparameter *moods* '(indicative subjunctive imperative))
  9. ;; TODO Visually organize all tenses
  10. (defparameter *indicative-tenses* '(present progressive present-perfect
  11.                     past-perfect preterit preterit-perfect imperfect
  12.                     future-ir future future-perfect conditional
  13.                     conditional-perfect))
  14. (defparameter *subjunctive-tenses* '(present imperfect future
  15.                          present-perfect past-perfect future-perfect))
  16. ;; Maybe rename symbols to tu/nosotros/etc.
  17. (defparameter *imperative-tenses* '(second-singular-informal
  18.                     second-plural-informal
  19.                     second-singular-formal
  20.                     second-plural-formal
  21.                     first-plural))
  22.  
  23. (defun index-from-right (str index) (- (length str) index))
  24. (defun last-n-chars (str n) (subseq str (index-from-right str n)))
  25. (defun max-length-of-strings (strings) (apply #'max (mapcar #'length strings)))
  26. (defun make-string-with-spaces (num-spaces)
  27.   (apply #'concatenate (append '(string) (loop for i from 1 to num-spaces collect " "))))
  28. (defun pad-string (str max-length)
  29.   (concatenate 'string str (make-string-with-spaces (- max-length (length str)))))
  30. (defun print-conjugated-verb (verb-with-endings)
  31.   (defun get-singular-tenses () (subseq verb-with-endings 0 3))
  32.   (let* ((plural-start-index (+ 2 (max-length-of-strings (get-singular-tenses))))
  33.      (singular-strings-ready (mapcar (lambda (str) (pad-string str plural-start-index))
  34.                            (get-singular-tenses)))
  35.      (plural-strings-ready (subseq verb-with-endings 3)))
  36.     (loop for singular in singular-strings-ready for plural in plural-strings-ready do
  37.            (format 't "~a~a~%" singular plural))))
  38. (defun warn-reflexive-not-implemented (verb)
  39.   (if (is-reflexive? verb) (print "Reflexive not imp")))
  40. ;; TODO Fix bug where reflexive verbs don't return their proper type.
  41. (defun get-verb-type (verb) (read-from-string (last-n-chars verb 2)))
  42. (defun is-reflexive? (verb) (equal (string-upcase (last-n-chars verb 3)) "RSE"))
  43. (defun get-verb-root (verb) (let ((last-index (if (is-reflexive? verb) 4 2)))
  44.                   (subseq verb 0 (index-from-right verb last-index))))
  45. ;; TODO fix reflexive verbs.
  46. (defun is-verb-type? (verb type) (eq (get-verb-type verb) type))
  47. (defun add-ending-to-infinative (verb ending)
  48.   (concatenate 'string (get-verb-root verb) ending))
  49. (defun get-conjugated-list (verb endings)
  50.   (loop for ending in endings collect (add-ending-to-infinative verb ending)))
  51.  
  52.  
  53. (defparameter +present-indicative-conjugations+
  54.   (list 'ar '("o" "as" "a" "amos" "áis" "an")
  55.     'er '("o" "es" "e" "emos" "éis" "en")
  56.     'ir '("o" "es" "e" "imos" "ís"  "en")))
  57.  
  58. (defparameter +preterit-indicative-conjugations+
  59.   (list 'ar '("é" "aste" "ó"  "amos" "asteis" "aron")
  60.     'er '("í" "iste" "ió" "imos" "isteis" "ieron")
  61.     'ir '("í" "iste" "ió" "imos" "isteis" "ieron")))
  62.  
  63. ;; Note that they are all the same.
  64. (defparameter +imperfect-indicative-conjugations+
  65.   (list 'ar '("ía" "ías" "ía" "íamos" "íais" "ían")
  66.     'er '("ía" "ías" "ía" "íamos" "íais" "ían")
  67.     'ir '("ía" "ías" "ía" "íamos" "íais" "ían")))
  68.  
  69. ;; Note that they are the same as the imperfect, except they keep the infinative
  70. ;; stem.
  71. (defparameter +conditional-indicative-conjugations+
  72.   (list 'ar '("aría" "arías" "aría" "aríamos" "aríais" "arían")
  73.     'er '("ería" "erías" "ería" "eríamos" "eríais" "erían")
  74.     'ir '("iría" "irías" "iría" "iríamos" "iríais" "irían")))
  75.  
  76.  
  77. (defun conj-present-indactive (verb)
  78.   (warn-reflexive-not-implemented verb)
  79.   (get-conjugated-list verb (getf +present-indicative-conjugations+
  80.                   (get-verb-type verb))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement