debugging

From: Trent Buck (trentbuck_at_gmail.com)
Date: 03/26/05


Date: Sat, 26 Mar 2005 08:44:23 GMT

Several times recently I've made the same mistake:

        (defun entropy (P &optional (K 2))
          "Take a probability alist and a base, return the overall entropy."
          (if (null P)
              0
              (+ (* (cdar P)
                    (- (log (cdar P) K)))
                 (entropy (cdr P)))))

instead of

        (defun entropy (P &optional (K 2))
          "Take a probability alist and a base, return the overall entropy."
          (if (null P)
              0
              (+ (* (cdar P)
                    (- (log (cdar P) K)))
                 (entropy (cdr P) K))))

That is, forgetting to include the optional argument when recursing.
Is there an easy way to detect this error?

-- 
Trent Buck, Student Errant
For their next act, they'll no doubt be buying a firewall running under NT,
which makes about as much sense as building a prison out of meringue.
 -- Tanuki


Relevant Pages