;;Zip the two lists lst1 and lst2 by means of z.

(define (zip z lst1 lst2) (if (null? lst1) '() (cons (z (car lst1) (car lst2)) (zip z (cdr lst1) (cdr lst2)))))
;;Compose a list of functions to a single function. ;; Each function in the list takes a single parameter. ;; Handles the typical case of two functions manually to achieve ;; better efficiency. ;; .precondition f-list is a proper list of length ast least one.

(define (compose . f-list) (cond ((= 1 (length f-list)) (car f-list)) ; ((= 2 (length f-list)) ; (let ((f (car f-list)) (g (cadr f-list))) (lambda (x) (f (g x))))) (else (lambda (x) ; ((car f-list) ((apply compose (cdr f-list)) x))))))
;;Filter lst by pred.

(define (filter pred lst) (reverse ; (filter-help pred lst '()))) ;The function that does the real filtering. ; A tail recursive function
(define (filter-help pred lst res) (cond ((null? lst) res) ((pred (car lst)) (filter-help pred (cdr lst) (cons (car lst) res))) (else (filter-help pred (cdr lst) res))))