is there any funtion to test wherther the given list is in ascending or descendin order
I saw one funtion INSEQA but ts not working
;;; By Indecipherable
;;; Checks if a list is in a disc. or asc. order, or neither.
(defun check (list)
(let ((list-dec (copy-list list)))
(let ((list-inc (copy-list list)))
(let ((alist (sort list-inc #'<)))
(let ((dlist (sort list-dec #'>)))
(cond
((equal alist list)
(format t "The list is in an ascending order."))
((equal dlist list)
(format t "The list is in a descending order.")))
(if
(not (equal alist list))
(if
(not (equal dlist list))
(format t "NO MATCH"))))))))
(apply #'< list)
Konfusius wrote:
- Code: Select all
(apply #'< list)
Konfusius wrote:
- Code: Select all
(apply #'< list)
(or (apply #'<= list) (apply #'>= list))
(defun orderedp (list)
(let ((order nil) (last (first list)))
(dolist (x (rest list) (or order :EQUAL))
(cond ((< x last)
(if (and order (eq order :ASCENDING))
(return nil)
(setq order :DESCENDING)))
((> x last)
(if (and order (eq order :DESCENDING))
(return nil)
(setq order :ASCENDING))))
(setq last x))))
Users browsing this forum: No registered users and 1 guest