sachac / artbollocks-mode

Emacs mode for highlighting weasel words
GNU Affero General Public License v3.0
74 stars 11 forks source link

Avoid divide by zero where document is empty or small #14

Closed mneilsen closed 9 years ago

mneilsen commented 9 years ago

I'm fine ditching the macro entirely--especially in favor of more explicit (readable) code. How does the following look? If this looks okay to you, I'll update the other functions accordingly.

(defun artbollocks-automated-readability-index (&optional start end)
  (let ((words (float (artbollocks-count-words start end)))
        (letters (float (artbollocks-count-letters start end)))
        (sentences (float (artbollocks-count-sentences start end))))
    (if (and (> words 0) (> sentences 0))
        (- (+ (* 4.71 (/ letters words))
              (* 0.5 (/ words sentences)))
           21.43)
      0.0)))
sachac commented 9 years ago

That looks beautiful. Thanks! :-D On Dec 5, 2014 2:57 PM, "mneilsen" notifications@github.com wrote:

I'm fine ditching the macro entirely--especially in favor of more explicit (readable) code. How does the following look? If this looks okay to you, I'll update the other functions accordingly.

(defun artbollocks-automated-readability-index (&optional start end) (let ((words (float (artbollocks-count-words start end))) (letters (float (arbollocks-count-letters start end))) (sentences (float (artbollocks-count-sentences start end)))) (if (and (> words 0) (> sentences 0)) (- (+ (* 4.71 (/ letters words)) (* 0.5 (/ words sentences))) 21.43) 0.0)))

— Reply to this email directly or view it on GitHub https://github.com/sachac/artbollocks-mode/pull/14#issuecomment-65845334 .