C.2.3 生成纵轴标注列

前面的函数已经提供了全部工具,我们可以据此构造一个函数,生成带编号与空白字符串的列表,用作纵轴标注:

(defun Y-axis-column (height width-of-label)
  "构造纵轴标注与空白字符串列表。
HEIGHT 为基线以上的行数,WIDTH-OF-LABEL 为标注宽度。"
  (let (Y-axis)
    (while (> height 1)
      (if (zerop (% height Y-axis-label-spacing))
          ;; Insert label.
          (setq Y-axis
                (cons
                 (Y-axis-element height width-of-label)
                 Y-axis))
        ;; Else, insert blanks.
        (setq Y-axis
              (cons
               (make-string width-of-label ? )
               Y-axis)))
      (setq height (1- height)))
    ;; 插入基线行。
    (setq Y-axis
          (cons (Y-axis-element 1 width-of-label) Y-axis))
    (nreverse Y-axis)))

在该函数中,我们从 height 的值开始,不断对其减 1。每次减法之后,判断该值是否为 Y-axis-label-spacing 的整数倍。如果是,就用 Y-axis-element 构造带编号的标注;否则用 make-string 构造空白标注。基线行是数字 1 后跟一个刻度标记。