cl:sorted?   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/runtime/scheme.xtm

Implementation

;;; (cl:sorted? sequence less?)
;;; is true when sequence is a list (x0 x1 ... xm) or a vector #(x0 ... xm)
;;; such that for all 1 <= i <= m,
;;;	(not (less? (list-ref list i) (list-ref list (- i 1)))).
;@
(define (cl:sorted? seq less?)
  (cond ((null? seq) #t)
  (else (let loop ((last (car seq)) (next (cdr seq)))
     (or (null? next)
         (and (not (less? (car next) last))
        (loop (car next) (cdr next))))))))


Back to Index