blob: 799b070f08cf59918bcbe91d8544ffbc9dd848d6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
(define-library (csc list)
(export
intercalate
revappend
split-at
take)
(import (scheme base)
(only (csc match)
match))
(begin
(define (take n xs)
(let loop ((n n)
(xs xs)
(acc '()))
(if (or (not (positive? n)) (null? xs))
(reverse acc)
(loop (- n 1) (cdr xs) (cons (car xs) acc)))))
(define (split-at n xs)
(let loop ((n n)
(xs xs)
(acc '()))
(if (or (not (positive? n)) (null? xs))
(values (reverse acc) xs)
(loop (- n 1) (cdr xs) (cons (car xs) acc)))))
(define (revappend a b)
(let loop ((xs a)
(acc b))
(if (null? xs)
acc
(loop (cdr xs) (cons (car xs) acc)))))
(define (intercalate x l)
(match l
('() '())
((_) l)
((head . tail) (cons head (cons x (intercalate x tail))))))))
|