scm.mes: add max, min.
This commit is contained in:
parent
e1bfc3e17e
commit
746d06a0ec
12
scm.mes
12
scm.mes
|
@ -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)))))
|
||||
|
|
8
test.mes
8
test.mes
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue