any function is there
Posted: Fri Jul 01, 2011 1:21 pm
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
I saw one funtion INSEQA but ts not working
Discuss and learn Lisp programming of all dialects. NOTICE: Site locked. No new users or posts.
http://www.lispforum.com/
Code: Select all
;;; 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"))))))))
Okay so obviously there are quite alot of waysKonfusius wrote:Code: Select all
(apply #'< list)
That doesn't work, because it's supposed to check if the list is either ascending or descending. You could doKonfusius wrote:Code: Select all
(apply #'< list)
Code: Select all
(or (apply #'<= list) (apply #'>= list))
Code: Select all
(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))))