tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 9ecbaa7ab7663d0a2b6fbb35f9de650b2727e65b
parent dde8a9369d5f76e2dfeb0828c2e732993c21ccf6
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat, 28 Dec 2019 21:41:34 -0800

Add error message to nth for out of bounds

Diffstat:
tibs/lib.tsp | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -121,11 +121,13 @@ (last (cdr lst)) (car lst))) +; TODO make nth generic for list str vec, made up of list-ref vec-ref str-ref (define (nth lst i) - (when (pair? lst) + (if (pair? lst) (if (<= i 0) (car lst) - (nth (cdr lst) (- i 1))))) + (nth (cdr lst) (- i 1))) + (error 'nth "index of list out bounds"))) (define (count x lst) (cond ((nil? lst) 0)