SICP問題2.57

(define (make-sum a b . rest)
  (letrec ((make-sum-sub (lambda (terms sum)
			   (cond [(zero? sum) (cond [(null? terms) 0]
						    [(null? (cdr terms))
						     (car terms)]
						    [else (cons '+ terms)])]
				 [(null? terms) sum]
				 [else (cons '+ (cons sum terms))]))))
    (let ((terms (filter
		   (lambda (x) (not (number? x)))
		   (cons a (cons b rest))))
	  (sum (fold + 0
		     (filter (lambda (x) (number? x))
			     (cons a (cons b rest))))))
      (make-sum-sub terms sum))))

(define (augend s) (if (null? (cdddr s))
		       (caddr s)
		       (apply make-sum (cddr s))))

(define (make-product a b . rest)
  (letrec ((make-product-sub (lambda (terms product)
			       (cond [(= product 0) 0]
				     [(= product 1) (cond [(null? terms) 1]
							  [(null? (cdr terms))
							   (car terms)]
							  [else (cons '* terms)])]
				     [(null? terms) product]
				     [else (cons '* (cons product terms))]))))
    (let ((terms (filter
		  (lambda (x) (not (number? x)))
		  (cons a (cons b rest))))
	  (product (fold * 1
			 (filter (lambda (x) (number? x))
				 (cons a (cons b rest))))))
      (make-product-sub terms product))))

(define (multiplicand p) (if (null? (cdddr p))
			     (caddr p)
			     (apply make-product (cddr p))))