jweinst1
12/7/2016 - 5:38 PM

list.scm

;Scheme List Methods;

;Appends to the end of a scheme list;
;   (append (list 1 2 3) 4)
;=> (1 2 3 4);
(define (append lst n)
  (if (null? lst)
      (cons n ())
      (cons (car lst) (append (cdr lst) n))
  )
)

;this function has an error, fix it;
(define (index lst i)
  (if (= i 0)
      (if (not (null? (cdr lst)))
          #f 
          (car lst)
      )
    (index lst (- i 1))
  )
)