Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 30 lines (25 sloc) 0.72 kb
ce2a689 @txus Lexer handles more generic cases, AST-builder draft
authored
1 (define (list-length lst)
2 (if (null? lst)
3 0
4 (+ 1 (list-length (cdr lst)))))
5
6 (define (append lst1 lst2)
7 (if (null? lst1)
8 lst2
9 (cons (car lst1) (append (cdr lst1) lst2))))
10
11 (define (list-reverse lst)
12 (if (null? lst)
13 '()
14 (append (list-reverse (cdr lst)) (list (car lst)) )))
15
16 ; Takes a list and returns a list of (cons elem elem) for each elem in the
17 ; given list.
18 ;
19 (define (pairify lst)
20 (if (null? lst)
21 '()
22 (cons
23 (cons (car lst) (car lst))
24 (pairify (cdr lst)))))
25
26 (write (list-length (list 1 2 3 4 5)))
27 (write (append '(1 2 3 4) (list 9)))
28 (write (list-reverse (list 1 2 3 4 5)))
29 (write (pairify (list 1 2 3 4)))
Something went wrong with that request. Please try again.