;; CS 3520 ;; Fall 2000 ;; HW 1 example solution ;; 1.1 (define (square x) (* x x)) (define (poly x) (+ (* 3 x x) (* 7 x) 42)) (define (xor a b) (and (or a b) (not (and a b)))) (define (sign x) (cond [(> x 0) 1] [(< x 0) -1] [else 0])) (define (sum-pair p) (+ (car p) (cdr p))) (define (flip p) (cons (cdr p) (car p))) (define (pair->list p) (list (car p) (cdr p))) (define (sym-in-pair? s p) (or (eq? s (car p)) (eq? s (cdr p)))) (define (two-elem-list? x) (and (pair? x) (pair? (cdr x)) (null? (cddr x)))) (define (make-five-list) '(1 2 3 4 5)) (define (make-identity-list) (list 'lambda (list 'x) 'x)) ;; 1.2 (define (answer-for-1.2) '(#t #f #t #t #t #t #f #f #t #t #f #t)) ;; 1.3 (define (step n) (cond [(= n 0) '(((lambda (x) (lambda (y) (- x y))) 2) 1)] [(= n 1) '((lambda (y) (- 2 y)) 1)] [(= n 2) '(- 2 1)] [else 1]))