ref: 169db4d362fbfcf10f77fe61a824906f7d413d78
parent: 0b4f5922cb2e5c693f4ed4fe54488de54f24e9f0
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat Jan 4 19:09:56 EST 2025
>=, <=: let loop
--- a/system.lsp
+++ b/system.lsp
@@ -176,11 +176,10 @@
(define (> a . rest)
"Return #t if the arguments are in strictly decreasing order (previous
one is greater than the next one)."
- (define (f a rest)
+ (let loop ((a a) (rest rest))
(or (null? rest)
(and (< (car rest) a)
- (f (car rest) (cdr rest)))))
- (f a rest))
+ (loop (car rest) (cdr rest))))))
(define-macro (> a . rest)
`(< ,@(reverse! rest) ,a))
@@ -187,22 +186,20 @@
(define (<= a . rest)
"Return #t if the arguments are in non-decreasing order (previous
one is less than or equal to the next one)."
- (define (f a rest)
- (unless (null? rest)
- (or (< (car rest) a)
- (nan? a)
- (f (car rest) (cdr rest)))))
- (not (f a rest)))
+ (let loop ((a a) (rest rest))
+ (or (null? rest)
+ (unless (or (< (car rest) a)
+ (nan? a))
+ (loop (car rest) (cdr rest))))))
(define (>= a . rest)
"Return #t if the arguments are in non-increasing order (previous
one is greater than or equal to the next one)."
- (define (f a rest)
- (unless (null? rest)
- (or (< a (car rest))
- (nan? a)
- (f (car rest) (cdr rest)))))
- (not (f a rest)))
+ (let loop ((a a) (rest rest))
+ (or (null? rest)
+ (unless (or (< a (car rest))
+ (nan? a))
+ (loop (car rest) (cdr rest))))))
(define-macro (/= a . rest)
"Return #t if not all arguments are equal. Shorthand for (not (= …))."