From d2cf1dc6577e15aabf2fa8508f3e16e107e302b4 Mon Sep 17 00:00:00 2001 From: Peter Lane Date: Tue, 9 May 2017 18:01:16 +0100 Subject: [PATCH 1/4] added test case and fix so ilist= works with more than 2 lists: copied from srfi-1 change --- ilists/ilists-impl.scm | 12 ++++++------ ilists/ilists-test.scm | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ilists/ilists-impl.scm b/ilists/ilists-impl.scm index be81815..2cd4915 100644 --- a/ilists/ilists-impl.scm +++ b/ilists/ilists-impl.scm @@ -292,13 +292,13 @@ (others (cdr others))) (if (eq? ilist-a ilist-b) ; EQ? => LIST= (lp1 ilist-b others) - (let lp2 ((ilist-a ilist-a) (ilist-b ilist-b)) - (if (null-ilist? ilist-a) - (and (null-ilist? ilist-b) + (let lp2 ((pair-a ilist-a) (pair-b ilist-b)) + (if (null-ilist? pair-a) + (and (null-ilist? pair-b) (lp1 ilist-b others)) - (and (not (null-ilist? ilist-b)) - (= (icar ilist-a) (icar ilist-b)) - (lp2 (icdr ilist-a) (icdr ilist-b))))))))))) + (and (not (null-ilist? pair-b)) + (= (icar pair-a) (icar pair-b)) + (lp2 (icdr pair-a) (icdr pair-b))))))))))) diff --git a/ilists/ilists-test.scm b/ilists/ilists-test.scm index 3ae2fac..1f924b9 100644 --- a/ilists/ilists-test.scm +++ b/ilists/ilists-test.scm @@ -30,6 +30,7 @@ (test-assert (not-ipair? 'a)) (test-assert (not (not-ipair? (ipair 'a 'b)))) (test-assert (ilist= = (iq 1 2 3) (iq 1 2 3))) + (test-assert (ilist= = (iq 1 2 3) (iq 1 2 3) (iq 1 2 3))) (test-assert (not (ilist= = (iq 1 2 3 4) (iq 1 2 3)))) (test-assert (not (ilist= = (iq 1 2 3) (iq 1 2 3 4)))) (test-assert (ilist= = (iq 1 2 3) (iq 1 2 3))) From 100ade5a99c473c6d2ed281e51e48115fc38e9da Mon Sep 17 00:00:00 2001 From: Peter Lane Date: Tue, 9 May 2017 18:04:16 +0100 Subject: [PATCH 2/4] ilist-copy should be exported: added test case and name to export list in .scm and .sld --- ilists/ilists-test.scm | 3 +++ ilists/ilists.scm | 2 +- ilists/ilists.sld | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ilists/ilists-test.scm b/ilists/ilists-test.scm index 1f924b9..9835615 100644 --- a/ilists/ilists-test.scm +++ b/ilists/ilists-test.scm @@ -14,6 +14,9 @@ (test (iq c c c c) (make-ilist 4 'c)) (test (iq 0 1 2 3) (ilist-tabulate 4 values)) (test (iq 0 1 2 3 4) (iiota 5)) + (define abc-copy (ilist-copy abc)) + (test abc abc-copy) + (test-assert (not (eq? abc abc-copy))) ) ; end ilists/constructors (test-group "ilists/predicates" diff --git a/ilists/ilists.scm b/ilists/ilists.scm index d79b6cb..79b0434 100644 --- a/ilists/ilists.scm +++ b/ilists/ilists.scm @@ -3,7 +3,7 @@ (import (only chicken include define-record-type define-record-printer error)) (export iq) - (export ipair ilist xipair ipair* make-ilist ilist-tabulate iiota) + (export ipair ilist xipair ipair* make-ilist ilist-copy ilist-tabulate iiota) (export ipair?) (export proper-ilist? ilist? dotted-ilist? not-ipair? null-ilist? ilist=) (export icar icdr ilist-ref) diff --git a/ilists/ilists.sld b/ilists/ilists.sld index f9112d0..80a3fff 100644 --- a/ilists/ilists.sld +++ b/ilists/ilists.sld @@ -1,7 +1,7 @@ (define-library (srfi-116) (import (scheme base)) (export iq) - (export ipair ilist xipair ipair* make-ilist ilist-tabulate iiota) + (export ipair ilist xipair ipair* make-ilist ilist-copy ilist-tabulate iiota) (export ipair?) (export proper-ilist? ilist? dotted-ilist? not-ipair? null-ilist? ilist=) (export icar icdr ilist-ref) From 4862f0ff3cc4fb2dd6ca9f27a8ecd40d14418538 Mon Sep 17 00:00:00 2001 From: Peter Lane Date: Tue, 9 May 2017 18:05:50 +0100 Subject: [PATCH 3/4] ievery only traversed one list: changed test case to expose error and fixed --- ilists/ilists-impl.scm | 2 +- ilists/ilists-test.scm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ilists/ilists-impl.scm b/ilists/ilists-impl.scm index 2cd4915..6692d5c 100644 --- a/ilists/ilists-impl.scm +++ b/ilists/ilists-impl.scm @@ -948,7 +948,7 @@ (define (ibreak pred lis) (ispan (lambda (x) (not (pred x))) lis)) (define (ievery pred lis1 . lists) (check-arg procedure? pred ievery) - (if (ipair? lists) + (if (pair? lists) ;; N-ary case (receive (heads tails) (%cars+cdrs (ipair lis1 lists)) diff --git a/ilists/ilists-test.scm b/ilists/ilists-test.scm index 9835615..69866a0 100644 --- a/ilists/ilists-test.scm +++ b/ilists/ilists-test.scm @@ -291,7 +291,7 @@ (test #t (iany < (iq 3 1 4 1 5) (iq 2 7 1 8 2))) (test #t (ievery integer? (iq 1 2 3 4 5))) (test #f (ievery integer? (iq 1 2 3 4.5 5))) - (test #t (ievery < (iq 1 2 3) (iq 4 5 6))) + (test #t (ievery (lambda (a b) (< a b)) (iq 1 2 3) (iq 4 5 6))) (test 2 (ilist-index even? (iq 3 1 4 1 5 9))) (test 1 (ilist-index < (iq 3 1 4 1 5 9 2 5 6) (iq 2 7 1 8 2))) (test #f (ilist-index = (iq 3 1 4 1 5 9 2 5 6) (iq 2 7 1 8 2))) From 4dd731eaf6577519a03f02be1caf30b687dd311f Mon Sep 17 00:00:00 2001 From: Peter Lane Date: Tue, 9 May 2017 18:06:53 +0100 Subject: [PATCH 4/4] altered test cases in ilists/searching to give an internal ilists error, not simple scheme error --- ilists/ilists-test.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ilists/ilists-test.scm b/ilists/ilists-test.scm index 69866a0..0c995f4 100644 --- a/ilists/ilists-test.scm +++ b/ilists/ilists-test.scm @@ -272,8 +272,8 @@ (test #t (iany even? (iq 1 2 3))) (test #f (ifind even? (iq 1 7 3))) (test #f (iany even? (iq 1 7 3))) - (test-error (ifind even? (ipair (1 (ipair 3 x))))) - (test-error (iany even? (ipair (1 (ipair 3 x))))) + (test-error (ifind even? (ipair 1 (ipair 3 'x)))) + (test-error (iany even? (ipair 1 (ipair 3 'x)))) (test 4 (ifind even? (iq 3 1 4 1 5 9))) (test (iq -8 -5 0 0) (ifind-tail even? (iq 3 1 37 -8 -5 0 0))) (test (iq 2 18) (itake-while even? (iq 2 18 3 10 22 9)))