;;; bob.el --- Bob exercise (exercism) ;;; Commentary: ;;; Code: (require 'cl-macs) (require 'seq) (cl-defstruct (utterance (:constructor utterance-create) (:copier nil)) is-question has-uppercase all-uppercase has-content) (defun utterance-is-yelling (utterance) (and (utterance-has-uppercase utterance) (utterance-all-uppercase utterance))) (defun update-utterance (utterance c) (let ((s (string c)) (case-fold-search nil)) (unless (string-match-p "[[:space:]]" s) (setf (utterance-is-question utterance) (eql ?? c)) (setf (utterance-has-content utterance) t) (when (string-match-p "[[:upper:]]" s) (setf (utterance-has-uppercase utterance) t)) (when (string-match-p "[[:lower:]]" s) (setf (utterance-all-uppercase utterance) nil))) utterance)) (defun response-for (message) (let* ((utterance (seq-reduce 'update-utterance message (utterance-create :is-question nil :has-uppercase nil :all-uppercase t :has-content nil))) (is-question (utterance-is-question utterance)) (is-yelling (utterance-is-yelling utterance))) (cond ((not (utterance-has-content utterance)) "Fine. Be that way!") ((and is-question is-yelling) "Calm down, I know what I'm doing!") ((and is-question (not is-yelling)) "Sure.") ((and (not is-question) is-yelling) "Whoa, chill out!" ) ((and (not is-question) (not is-yelling)) "Whatever." )))) (provide 'bob) ;;; bob.el ends here