;local variables
(define a '(3 6))
(let ([end1 (car a)]
      [end2 (cadr a)])
  (and (< end1 0) (> end2 0)))
	
(cons 1 2)
(cons 1 '())
'(1 . ())
(define x '())
(cons 1 (cons 2 x))

(define impr (cons 1 (cons 2 3)))
impr
(pair? impr)
(list? impr)



; start with code from yesterday

(define fact
  (lambda (n)
    (if (zero? n)
	1
	(* n (fact (- n 1))))))
	
	
(define nth-element ; finds the zero-based nth element in a list
  (lambda (ls n)
    (if (null? ls)
	"error"
	(if (zero? n)
	    (car ls)
	    (nth-element (cdr ls) (- n 1))))))

(define nth-element ; finds the zero-based nth element in a list
  (lambda (ls n)
    (cond [(null? ls) 	"error"]
	  [(zero? n)(car ls)]
	  [else  (nth-element (cdr ls) (- n 1))])))


(define fact
  (lambda (n)
    (if (negative? n)
	"error"
	(if (zero? n)
	    1
	    (* n (fact (- n 1)))))))

(define fact2
  (lambda (n)
    (if (negative? n)
	"error"
	(fact-acc n 1))))

(define fact-acc
  (lambda (n acc)
    (if (zero? n)
	acc
	(fact-acc (- n 1) (* n acc)))))