commit 333cfe51b8225555dfa42b291461793bbbfe761b
parent f53803f3cb3acfa29a6339c4a1ed54fb3e3f564d
Author: Ed van Bruggen <edvb@uw.edu>
Date: Thu, 19 Sep 2019 23:47:48 -0700
Switch order of function and list in foreach
Diffstat:
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/tibs/lib.tsp b/tibs/lib.tsp
@@ -100,16 +100,16 @@
(define (apply fn args)
(eval (cons fn args)))
-(define (foreach fn args)
+(define (foreach args fn)
(unless (nil? args)
(fn (car args))
- (foreach fn (cdr args))))
+ (foreach (cdr args) fn)))
(define (map fn lst)
- (cond
- (lst (cons (fn (car lst))
- (map fn (cdr lst))))
- (else ())))
+ (if lst
+ (cons (fn (car lst))
+ (map fn (cdr lst)))
+ nil))
(define (append l1 l2)
(cond ((nil? l1) l2)
@@ -132,7 +132,7 @@
(define (truncate x) (* (floor (abs x)) (sgn x)))
(define (sqr x) (* x x))
-(define (root b p) (^ b (/ 1 p)))
+(define (root b p) (^ b (/ p)))
(define (sqrt x) (root x 2))
(define (cbrt x) (root x 3))
(define (logb b x) (/ (log x) (log b)))
@@ -158,9 +158,9 @@
(define (newline) (print "\n"))
(define (disp . str) (apply print str) (newline))
(define (disp-string . str)
- (foreach (lambda (s)
+ (foreach str
+ (lambda (s)
(if (string? s)
(print "\"" s "\"")
- (print s)))
- str)
+ (print s))))
(newline))