#lang racket
(define (map f l)
(if (null? l)
null
(cons (f (car l)) (map f (cdr l)))))
(define (range n)
(if (= n 0)
null
(cons n (range (- n 1)))))
(define (sum1 xs)
(if (null? xs)
0
(if (number? (car xs))
(+ (car xs) (sum1 (cdr xs)))
(+ (sum1 (car xs)) (sum1 (cdr xs))))))
(define (append xs ys)
(if (null? xs)
ys
(cons (car xs) (append (cdr xs) ys))))
(define (foldl f base xs)
(if (null? xs)
base
(foldl f (f (car xs) base) (cdr xs))))
(define (foldr f base xs)
(if (null? xs)
base
(f (car xs) (foldr f base (cdr xs)))))
(define (sum-anything a)
(if (null? a)
0
(if (list? a)
(if (number? (car a))
(+ (car a) (sum-anything (cdr a)))
(+ (sum-anything (car a))
(sum-anything (cdr a))))
(if (number? a)
a
0))))
(define (sum2 a)
(cond [(number? a) a]
[(pair? a) (+ (sum2 (car a)) (sum2 (cdr a)))]
[#t 0]))