(define mapcar-form
    '(define mapcar (lambda (f l)
        (if (null? l)
	    nil
	    (cons (f (car l)) (mapcar f (cdr l)))))))

(define square-form
    '(define square (lambda (x) (* x x))))

(define gen-tree-form '(define gen-tree (lambda (n)
    (if (= n 0)
	23
	(let ((j (- n 1)))
	  (cons (gen-tree j) (gen-tree j))))))) 

(define fringe-form '(define fringe (lambda (tree) (fringe-aux tree nil))))

(define fringe-aux-form '(define fringe-aux (lambda (tree lst)
    (if (null? tree)
	lst
	(if (atom? tree)
	    (cons tree lst)
	    (fringe-aux (car tree)
                        (fringe-aux (cdr tree) lst)))))))

(define count-atoms-r-form '(define count-atoms-r (lambda (lst)
    (if (null? lst)
	0
	(if (atom? lst)
	    1
	    (+ (count-atoms-r (car lst))
	       (count-atoms-r (cdr lst))))))))

(define count-atoms-i-form '(define count-atoms-i (lambda (lst)
    (count-atoms-i-loop lst nil 0))))

(define count-atoms-i-loop-form '(define count-atoms-i-loop (lambda (l1 l2 n)
    (if (null? l1)
	(if (null? l2)
	    n
	    (count-atoms-i-loop (car l2) (cdr l2) n))
	(if (atom? l1)
	    (if (null? l2)
		(+ n 1)
		(count-atoms-i-loop (car l2) (cdr l2) (+ n 1)))
	    (count-atoms-i-loop (car l1) (cons (cdr l1) l2) n))))))

(define fibs-form
 '(define fibs (lambda (n)
    (letrec
          ((L        (fibs-aux 0 L))
	   (fibs-aux (lambda (j L)
		       (if (> j n)
			   nil
			   (let ((x (if (< j 2)
					1
			                (+ (list-ref L (- j 1))
					   (list-ref L (- j 2))))))
			     (cons x (fibs-aux (+ j 1) L)))))))
       L))))
