;; test functions and definitions for MiniScheme project (define nil ()) (define reverse (lambda (x) (define reverseh (lambda (y a) (cond ((null? y) a) (#t (reverseh (cdr y) (cons (car y) a)))))) (reverseh x nil))) (define and (lambda (x y) (cond (x y) (#t #f)))) (define equal? (lambda (x y) (cond ((and (atom? x) (atom? y)) (eq? x y)) ((atom? x) nil) ((atom? y) nil) (#t (and (equal? (car x) (car y)) (equal? (cdr x) (cdr y))))))) (define map (lambda (f l) (cond ((null? l) nil) (#t (cons (f (car l)) (map f (cdr l))))))) (define filter (lambda (pred l) (cond ((null? l) nil) ((pred (car l)) (filter pred (cdr l))) (#t (cons (car l) (filter pred (cdr l))))))) (define insert (lambda (e l) (cond ((null? l) (cons e l)) ((< e (car l)) (cons e l)) (#t (cons (car l) (insert e (cdr l))))))) (define isort (lambda (l) (define isort-help (lambda (l sorted-l) (cond ((null? l) sorted-l) (#t (isort-help (cdr l) (insert (car l) sorted-l)))))) (isort-help l nil))) (define append (lambda (x y) (cond ((null? x) y) (#t (cons (car x) (append (cdr x) y))))))