[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/jwHWMEXX    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Dec 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
; split

(define (split xs)
  (let loop ((ts xs) (hs xs) (zs (list)))
    (if (or (null? hs) (null? (cdr hs)))
        (values (reverse zs) ts)
        (loop (cdr ts) (cddr hs) (cons (car ts) zs)))))

(define (display-split xs)
  (call-with-values
    (lambda () (split xs))
    (lambda (front back)
      (display front) (newline)
      (display back) (newline))))

(display-split '()) (newline)
(display-split '(1)) (newline)
(display-split '(1 2)) (newline)
(display-split '(1 2 3)) (newline)
(display-split '(1 2 3 4)) (newline)
(display-split '(1 2 3 4 5)) (newline)


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
()
()

()
(1)

(1)
(2)

(1)
(2 3)

(1 2)
(3 4)

(1 2)
(3 4 5)



Create a new paste based on this one


Comments: