punnet-squares.lisp 1.0 KB

123456789101112131415161718192021222324252627282930
  1. (ql:quickload :cl-who)
  2. (use-package 'cl-who)
  3. (defun punnett (parent-a parent-b &optional (type :mono))
  4. (declare (string parent-a parent-b)
  5. (keyword type))
  6. (case type
  7. (:mono
  8. (let* ((a (map 'list #'(lambda (x) (format nil "~c" x))
  9. parent-a))
  10. (b (map 'list #'(lambda (x) (format nil "~c" x))
  11. parent-b))
  12. (lena (length a))
  13. (lenb (length b)))
  14. (if (not (= lena lenb))
  15. (if (< lena lenb)
  16. (error "a < b, ~a < ~a" lena lenb)
  17. (error "a > b, ~a > ~a" lena lenb))
  18. (loop for from-b in b
  19. collect (loop for from-a in a
  20. collect (concatenate 'string from-a from-b))))))))
  21. (defun punnett-html (string-a string-b &optional (type :mono))
  22. (declare (ignore type))
  23. (with-html-output-to-string (out)
  24. (:table
  25. (loop for line in (punnett string-a string-b)
  26. do (htm (:tr (loop for cell in line
  27. do (htm (:td (str cell))))))))))