summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib.c32
-rw-r--r--tests/012/seq.tl33
2 files changed, 54 insertions, 11 deletions
diff --git a/lib.c b/lib.c
index 4883e08b..206eead7 100644
--- a/lib.c
+++ b/lib.c
@@ -9491,17 +9491,27 @@ static val window_map_list(val range, val boundary, val fun, val list,
args_set_fill(args, ws);
- if (boundary == wrap_k) {
- val lcopy = take(range, list);
- while (lt(length(lcopy), range))
- lcopy = append2(lcopy, lcopy);
- boundary = append2(sub(lcopy, num_fast(-ra), t), sub(lcopy, zero, range));
- } else if (boundary == reflect_k) {
- val lcopy = take(range, list);
- while (lt(length(lcopy), range))
- lcopy = append2(lcopy, lcopy);
- boundary = nappend2(nreverse(sub(lcopy, zero, range)),
- nreverse(sub(lcopy, num_fast(-ra), t)));
+ if (boundary == wrap_k || boundary == reflect_k) {
+ val lw = sub(list, num_fast(-ra), t), lwing = lw;
+ val rw = sub(list, zero, range), rwing = rw;
+ cnum i, len = c_fixnum(length(list), self);
+
+ if (boundary == reflect_k) {
+ lwing = reverse(rw);
+ rwing = reverse(lw);
+ lw = lwing;
+ rw = rwing;
+ }
+
+ for (i = len; i < ra; i += len) {
+ lwing = append2(lwing, lw);
+ rwing = append2(rwing, rw);
+ }
+
+ if (len < ra)
+ boundary = append2(sub(lwing, num_fast(-ra), t), sub(rwing, zero, range));
+ else
+ boundary = append2(lwing, rwing);
}
for (i = 0; i < ra; i++)
diff --git a/tests/012/seq.tl b/tests/012/seq.tl
index 1bb4ddcc..b38d226f 100644
--- a/tests/012/seq.tl
+++ b/tests/012/seq.tl
@@ -20,3 +20,36 @@
(test (mapcar (lambda (. args) (list . args)) '#(1 2 3) '#(4 5 6))
#((1 4) (2 5) (3 6)))
+
+(test [window-map 2 '(x x) list '(a b c d e f g)]
+ ((x x a b c) (x a b c d) (a b c d e)
+ (b c d e f) (c d e f g) (d e f g nil)
+ (e f g nil nil)))
+
+(test [window-map 2 '(x x y y) list '(a b c d e f g)]
+ ((x x a b c) (x a b c d) (a b c d e)
+ (b c d e f) (c d e f g) (d e f g y)
+ (e f g y y)))
+
+(test [window-map 2 nil list '(a b c d e f g)]
+ ((nil nil a b c) (nil a b c d) (a b c d e)
+ (b c d e f) (c d e f g)
+ (d e f g nil) (e f g nil nil)))
+
+(test [window-map 2 :wrap list '(a b c d e f g)]
+ ((f g a b c) (g a b c d) (a b c d e) (b c d e f)
+ (c d e f g) (d e f g a) (e f g a b)))
+
+(test [window-map 2 :reflect list '(a b c d e f g)]
+ ((b a a b c) (a a b c d) (a b c d e) (b c d e f)
+ (c d e f g) (d e f g g) (e f g g f)))
+
+(test [window-map 7 :wrap list '(a b c)]
+ ((c a b c a b c a b c a b c a b)
+ (a b c a b c a b c a b c a b c)
+ (b c a b c a b c a b c a b c a)))
+
+(test [window-map 7 :reflect list '(a b c)]
+ ((a c b a c b a a b c c b a c b)
+ (c b a c b a a b c c b a c b a)
+ (b a c b a a b c c b a c b a c)))