Go to the first, previous, next, last section, table of contents.


Another Bug ... Most Insidious

I said `almost ready to print'! Of course, there is a bug in the print-graph function ... It has a vertical-step option, but not a horizontal-step option. The top-of-range scale goes from 10 to 300 by tens. But the print-graph function will print only by ones.

This is a classic example of what some consider the most insidious type of bug, the bug of omission. This is not the kind of bug you can find by studying the code, for it is not in the code; it is an omitted feature. Your best actions are to try your program early and often; and try to arrange, as much as you can, to write code that is easy to understand and easy to change. Try to be aware, whenever you can, that whatever you have written, will be rewritten, if not soon, eventually. A hard maxim to follow.

It is the print-X-axis-numbered-line function that needs the work; and then the print-X-axis and the print-graph functions need to be adapted. Not much needs to be done; there is one nicety: the numbers ought to line up under the tic marks. This takes a little thought.

Here is the corrected print-X-axis-numbered-line:

(defun print-X-axis-numbered-line
  (number-of-X-tics X-axis-leading-spaces
   &optional horizontal-step)
  "Print line of X-axis numbers"
  (let ((number X-axis-label-spacing)
        (horizontal-step (or horizontal-step 1)))
    (insert X-axis-leading-spaces)
    ;; Delete extra leading spaces.
    (delete-char
     (- (1-
         (length (int-to-string horizontal-step)))))
    (insert (concat  
             (make-string 
              ;; Insert white space.
              (-  (* symbol-width
                     X-axis-label-spacing) 
                  (1-
                   (length
                    (int-to-string horizontal-step)))
                  2)
              ? )
             (int-to-string
              (* number horizontal-step))))
    ;; Insert remaining numbers.
    (setq number (+ number X-axis-label-spacing))
    (while (> number-of-X-tics 1)
      (insert (X-axis-element
               (* number horizontal-step)))
      (setq number (+ number X-axis-label-spacing))
      (setq number-of-X-tics (1- number-of-X-tics)))))

If you are reading this in Info, you can see the new versions of print-X-axis print-graph and evaluate them. If you are reading this in a printed book, you can see the changed lines here (the full text is too much to print).

(defun print-X-axis (numbers-list horizontal-step)
  ...
    (print-X-axis-numbered-line
     tic-number leading-spaces horizontal-step))
(defun print-graph
  (numbers-list
   &optional vertical-step horizontal-step)
  ...
    (print-X-axis numbers-list horizontal-step))


Go to the first, previous, next, last section, table of contents.