;;; $Id: nth-element-mod.scm,v 1.2 2006/01/05 22:24:09 leavens Exp $ ;;; AUTHOR: Dalei Li and Gary T. Leavens (module nth-element-mod (lib "typedscm.ss" "typedscm") (provide nth-element) (deftype nth-element (forall (t) (-> ((list-of t) number) t))) (define nth-element (lambda (lst n) ;; ENSURES: Result is the nth, zero-based, element of lst (if (null? lst) (eopl:error 'nth-element "List too short by ~s elements" (+ n 1)) (if (zero? n) (car lst) (nth-element (cdr lst) (- n 1)))))) ) ;; end module