• Jump To … +
    LICENSE.lisp abcd.lisp boot.lisp div.lisp fft.lisp index.lisp lib.lisp lib0.lisp num.lisp sample.lisp summary.lisp sym.lisp table.lisp tests.lisp weather.lisp
  • Fork me on GitHub

    home | issues | license

    CRAM: summary


  • ¶
    (in-package :cram)
    
    (needs "../src/lib")
    
    (defthing summary thing
      (txt "") (pos 0) (n 0) (w 1))
     
    (defmethod add1((x summary) y)
      (declare (ignore x y))
      (assert nil () "add1 should be implemented by subclass"))
    
    (defmethod norm1((x summary) y)
      (declare (ignore x y))
      (assert nil () "norm1 should be implemented by subclass"))
    
    (defmethod add ((x summary) y &optional (f #'identity))
      (with-slots (n) x
        (when (not (eql y #\?))
          (incf n)
          (add1 (funcall f x) y ))
        y))
    
    (defmethod adds ((x summary) (ys cons) &optional (f #'identity))
      (dolist (y ys x)
        (add x y f)))
    
    (defmethod adds ((x summary) (ys simple-vector) &optional (f #'identity))
      (loop for y across ys do 
            (add x y f)))
      
    (defmethod norm ((x summary) y)
      (if (eql y #\?) y (norm1 x y)))