commit 7c9bf31bcfecfc1ff89adfa2c9d681319c998a12
parent 5325d24e541ef6c76059e880132fbdaeb4da2d70
Author: Ed van Bruggen <edvb@uw.edu>
Date: Wed, 13 Nov 2019 18:41:14 -0800
Change order of nth function arguments
Diffstat:
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/test.c b/test.c
@@ -240,21 +240,21 @@ char *tests[][2] = {
{ "(list* (sqr 3) (cube 4))", "(9 . 64)" },
{ "(list* 5/4)", "5/4" },
- { "list get", NULL },
- { "(last '(1 2 3))", "3" },
- { "(last (list 4 5))", "5" },
- { "(last '(a b c d e f))", "f" },
- { "(last (cons 1 (cons 2 ())))", "2" },
- { "(length '(1 2 3))", "3" },
- { "(length (list .3 -3/2 12 5))", "4" },
- { "(length '(a b))", "2" },
- { "(length (list list))", "1" },
- { "(length ())", "0" },
- { "(length nil)", "0" },
- { "(nth 1 '(1 2 3))", "2" },
- { "(nth 2 (list 3 5/2 .332 -2))", "0.332" },
- { "(nth 0 '(a b c))", "a" },
- { "(nth 3 (list 'foo 'bar 'zar 'baz))", "baz" },
+ { "list get", NULL },
+ { "(last '(1 2 3))", "3" },
+ { "(last (list 4 5))", "5" },
+ { "(last '(a b c d e f))", "f" },
+ { "(last (cons 1 (cons 2 ())))", "2" },
+ { "(length '(1 2 3))", "3" },
+ { "(length (list .3 -3/2 12 5))", "4" },
+ { "(length '(a b))", "2" },
+ { "(length (list list))", "1" },
+ { "(length ())", "0" },
+ { "(length nil)", "0" },
+ { "(nth '(1 2 3) 1)", "2" },
+ { "(nth (list 3 5/2 .332 -2) 2)", "0.332" },
+ { "(nth '(a b c) 0)", "a" },
+ { "(nth (list 'foo 'bar 'zar 'baz) 3)", "baz" },
{ "apply", NULL },
{ "(apply list '(1 2 3))", "(1 2 3)" },
diff --git a/tibs/lib.tsp b/tibs/lib.tsp
@@ -113,11 +113,11 @@
(last (cdr lst))
(car lst)))
-(define (nth i lst)
+(define (nth lst i)
(when (pair? lst)
(if (<= i 0)
(car lst)
- (nth (- i 1) (cdr lst)))))
+ (nth (cdr lst) (- i 1)))))
(define (apply proc args)
(eval (map (lambda (x) ; prevent args from being evaluated twice