scm.mes: add max, min.

This commit is contained in:
Jan Nieuwenhuizen 2016-07-24 16:34:54 +02:00
parent e1bfc3e17e
commit 746d06a0ec
2 changed files with 20 additions and 0 deletions

12
scm.mes
View file

@ -176,6 +176,18 @@
(define quotient /)
(define (max x . rest)
(if (null? rest) x
(let* ((y (car rest))
(z (if (> x y) x y)))
(apply max (cons z (cdr rest))))))
(define (min x . rest)
(if (null? rest) x
(let* ((y (car rest))
(z (if (< x y) x y)))
(apply min (cons z (cdr rest))))))
(define (list? x)
(or (null? x)
(and (pair? x) (list? (cdr x)))))

View file

@ -277,6 +277,14 @@
(pass-if "<=" (seq? (<= 3 2 1) #f))
(pass-if "<= 2" (seq? (<= 1 2 3) #t))
(pass-if "max" (seq? (max 0) 0))
(pass-if "max 1" (seq? (max 0 1) 1))
(pass-if "max 2" (seq? (max 1 0 2) 2))
(pass-if "min" (seq? (min 0) 0))
(pass-if "min 1" (seq? (min 0 1) 0))
(pass-if "min 2" (seq? (min 1 0 2) 0))
(newline)
(display "passed: ") (display (car (result))) (newline)
(display "failed: ") (display (cadr (result))) (newline)