[ create a new paste ] login | about

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

programmingpraxis - Scheme, pasted on Feb 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
; an early lisp program

(define (atom? x)
  (and (not (pair? x)) (not (null? x))))

(define (collapse l)
  (cond ((atom? l) (cons l '()))
        ((null? (cdr l))
          (cond ((atom? (car l)) l)
                (else (collapse (car l)))))
        (else (append (collapse (car l))
                      (collapse (cdr l))))))

(display (collapse '((((a b) ((c))) ((d (e f)) (g) ((h))))))) (newline)
(display (collapse '((a (b (c (d (e))) f (g (h j))))))) (newline)
(display (collapse '((((((a) b) c) d) e)))) (newline)


Output:
1
2
3
(a b c d e f g h)
(a b c d e f g h j)
(a b c d e)


Create a new paste based on this one


Comments: