tisp

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

commit ab055d71ddf82410dc2209d96701b21decf39a69
parent 15021c575138e4842d8fd41764bd99b5699b2caa
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat, 27 Jul 2019 17:26:58 -0700

Add nth function to get numbered elemented of list

Diffstat:
tibs/lib.tsp | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -82,10 +82,18 @@ (define first car) (define rest cdr) (define (list . lst) lst) + (define (last lst) (cond ((cdr lst) (last (cdr lst))) (else (car lst)))) + +(define (nth i l) + (when (pair? l) + (if (<= i 0) + (car l) + (nth (- i 1) (cdr l))))) + (define (apply fn args) (eval (cons fn args))) (define (map fn lst)