add min and max

This commit is contained in:
Yuichi Nishiwaki 2013-11-14 21:58:30 +09:00
parent 066575fa1c
commit cc1adb93ce
1 changed files with 12 additions and 0 deletions

View File

@ -286,6 +286,18 @@
((pair? nums) acc) ((pair? nums) acc)
(set! acc (* acc (car nums))))) (set! acc (* acc (car nums)))))
(define (min x . args)
(let loop ((pivot x) (rest args))
(if (null? rest)
pivot
(loop (if (< x (car rest)) x (car rest)) (cdr rest)))))
(define (max x . args)
(let loop ((pivot x) (rest args))
(if (null? rest)
pivot
(loop (if (> x (car rest)) x (car rest)) (cdr rest)))))
;;; so ugly code, must rewrite everything as soon as possible... ;;; so ugly code, must rewrite everything as soon as possible...
(define-macro (define-transitive-predicate op) (define-macro (define-transitive-predicate op)
`(define (,op . args) `(define (,op . args)