diff --git a/src/text/stem-and-leaf.lisp b/src/text/stem-and-leaf.lisp index f1f0aa6..38a2050 100644 --- a/src/text/stem-and-leaf.lisp +++ b/src/text/stem-and-leaf.lisp @@ -1,13 +1,15 @@ ;;; -*- Mode: Lisp; Package: PLOT/TEXT; Syntax: ANSI-Common-Lisp; -*- -;;; Copyright (c) 2021-2022 by Symbolics Pte. Ltd. All rights reserved. +;;; Copyright (c) 2021-2023 by Symbolics Pte. Ltd. All rights reserved. +;;; SPDX-License-identifier: MS-PL + (in-package #:plot/text) (defun leaf-strings (all-stems all-leaves sort-order) "Returns a hashtable where the key represents the stem, and the value represents the leaves as a string." - (let ((max-stem (sequence-maximum all-stems)) + (let ((max-stem (seq-max all-stems)) (strings (make-hash-table :size 1000))) - (loop for s from (sequence-minimum all-stems) to max-stem + (loop for s from (seq-min all-stems) to max-stem for stems = (which all-stems :predicate #'(lambda (x) (= x s))) for leaves = (if (= (length stems) 0) nil @@ -28,9 +30,9 @@ (check-type x vector) (let* ((all-stems (efloor (e/ x (if split-stems (/ stem-size 2) stem-size)))) (all-leaves (emod x stem-size)) - (stem-fmt (format nil "~~~AD |" (length (format nil "~A" (sequence-maximum all-stems))))) + (stem-fmt (format nil "~~~AD |" (length (format nil "~A" (seq-max all-stems))))) (leaf-strings-vector (leaf-strings all-stems all-leaves #'<))) - (loop for s from (sequence-minimum all-stems) to (sequence-maximum all-stems) + (loop for s from (seq-min all-stems) to (seq-max all-stems) do (progn (format t stem-fmt (if split-stems (floor (/ s 2)) s)) (format t "~A~%" (gethash s leaf-strings-vector)))))) @@ -52,11 +54,11 @@ (combined-stems (concatenate 'vector left-stems right-stems)) (left-leaves (emod x stem-size)) (right-leaves (emod y stem-size)) - (stem-fmt (format nil " | ~~~AD |" (length (format nil "~A" (sequence-maximum combined-stems))))) + (stem-fmt (format nil " | ~~~AD |" (length (format nil "~A" (seq-max combined-stems))))) (left-strings (leaf-strings left-stems left-leaves #'>)) (right-strings (leaf-strings right-stems right-leaves #'<)) - (left-min-col (sequence-maximum (loop for leaf being each hash-value of left-strings collect (length leaf))))) - (loop for s from (sequence-minimum combined-stems) to (sequence-maximum combined-stems) + (left-min-col (seq-max (loop for leaf being each hash-value of left-strings collect (length leaf))))) + (loop for s from (seq-min combined-stems) to (seq-max combined-stems) do (progn (format t "~v@A" left-min-col (gethash s left-strings "")) (format t stem-fmt s) (format t "~A~%" (gethash s right-strings ""))))))