Problem 5: Ordered (100 pts)
Implement a procedure called ordered
, which takes a non-empty list of numbers and returns True
if the numbers are in nondescending order, and False
otherwise. Numbers are considered nondescending if each subsequent number is either larger or equal to the previous, that is:
1 2 3 3 4
Is nondescending, but:
1 2 3 3 2
Is not.
Hint: The built-in
null?
function returns whether its argument isnil
.
(define (ordered s)
'YOUR-CODE-HERE
)
;;; Tests
; scm> (ordered '(1 2 3 3 4))
; #t
; scm> (ordered '(1 2 3 3 2))
; #f